• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Force closes before even opening

Booocubs

Newbie
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! :)
 
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)
 
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 :)
 
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 :)
 
Back
Top Bottom