Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old October 24th, 2011, 05:44 PM   #1 (permalink)
New Member
 
Join Date: Oct 2011
Posts: 8
 
Device(s):
Thanks: 6
Thanked 0 Times in 0 Posts
Unhappy Force closes before even opening

Hey guys, I'm working on this new app, and it's force closing before it even opens, any idea as to why it's force closing? (I've tried this app on my samsung transform and my motorola xoom yesterday, both worked, and them i added the image button inplace of the regular button, and now it won't work. here are my files;

Main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine" >
        <requestFocus />
    </EditText>

    <ImageButton 
  		android:id="@+id/button1"
  		android:src="@drawable/pencil"
  		android:layout_width="fill_parent"
  		android:layout_height="wrap_content"
  		android:background="#000000" >
    </ImageButton>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>
.java file
Code:
package com.sevengangs.notetoself;

import java.util.ArrayList;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

public class NoteToSelfActivity extends Activity {
    
	final ArrayList<String> noteList = new ArrayList<String>();
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setRequestedOrientation(
        ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setContentView(R.layout.main);

        ListView view1 = (ListView) findViewById(R.id.listView1);
        
        final EditText editText1 = (EditText) findViewById(R.id.editText1);
        
        final ArrayAdapter<String> aa;
        
        aa = new ArrayAdapter<String>(this, R.layout.custom_list_item, R.id.noteText, noteList);
        
        view1.setAdapter(aa);
        
        Button button1 = (Button) findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener() {
        
        	public void onClick(View v) {
        		noteList.add(0, editText1.getText().toString());
        		editText1.setText("");
        	}
    
        });
    
    
    }
}
My custom list
Code:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/noteText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
	android:textColor="#00FF33"
	android:textSize="20px"
	android:gravity="center_horizontal" >
</TextView>
Thank you in advance!

Booocubs is offline  
Reply With Quote
Sponsors
Old October 25th, 2011, 06:07 AM   #2 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 308
 
Device(s): Samsung Galaxy Nexus
Thanks: 0
Thanked 52 Times in 51 Posts
Default

I think the problem is that you are trying to get a handler for an ImageButton and instantiate it as a regular Button. Try to replace:
Code:
Button button1 = (Button)
with this:
Code:
ImageButton button1 = (ImageButton)
__________________
Android: Personal Storage, Lars Monsen Facts(Norwegian)
miXer is offline  
Reply With Quote
The Following User Says Thank You to miXer For This Useful Post:
Booocubs (October 26th, 2011)
Old October 25th, 2011, 12:00 PM   #3 (permalink)
Senior Member
 
TheCompBoy's Avatar
 
Join Date: Oct 2010
Location: Sweden
Posts: 594
 
Device(s): Samsung Galaxy S w DarkyROM v10.1
Thanks: 4
Thanked 56 Times in 51 Posts
Send a message via Skype™ to TheCompBoy
Default

Maybe you could post the error log from LogCat?
__________________
Please check out my blogg: www.thecompboy.blogspot.com
If you want to support me please subscribe / follow the blogg!

OCalc - First App: https://market.android.com/details?id=mendel.calculator.simple&feature=search _result
TheCompBoy is offline  
Reply With Quote
Old October 25th, 2011, 08:32 PM   #4 (permalink)
New Member
 
Join Date: Oct 2011
Posts: 8
 
Device(s):
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by miXer View Post
I think the problem is that you are trying to get a handler for an ImageButton and instantiate it as a regular Button. Try to replace:
Code:
Button button1 = (Button)
with this:
Code:
ImageButton button1 = (ImageButton)
Now mixer, I now realize I am ******ed for missing that.. thank you but do I have to use

Code:
<ImageButton>
   .............................
   .............................
   .............................
</ImageButton>
or
Code:
<Button>
   .............................
   .............................
   .............................
</Button>
for my .xml code. thanks again
Booocubs is offline  
Reply With Quote
Old October 26th, 2011, 05:11 AM   #5 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 308
 
Device(s): Samsung Galaxy Nexus
Thanks: 0
Thanked 52 Times in 51 Posts
Default

That depends on what you want. If you want a Button with an image, go for ImageButton. If you want a button with text, go for Button. As long as the code uses the same class you are good to go
miXer is offline  
Reply With Quote
The Following User Says Thank You to miXer For This Useful Post:
Booocubs (October 26th, 2011)
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:10 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo