Sathish
Sathish

Reputation: 1147

Android app unable to start, activity error

Code for the Activity:

public class MainActivity extends Activity {

    private ListView lv;
    private CustomAdapter adapter;
    private ArrayList<Event> fetch = new ArrayList<Event>();
    private Button button;
    int counter = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

            adapter = new CustomAdapter(MainActivity.this, R.id.listview,fetch);
        lv.setAdapter(adapter);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Event temp=new Event("Date","Details","GeoLocation","Location","EvtName");
                fetch.add(temp);
                counter++;
                adapter.notifyDataSetChanged();

            } });

    }

}

The app fails, with Unable to start Activity componentInfo error. Logcat is:

05-06 12:56:34.248: E/AndroidRuntime(2215): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nasotech/com.nasotech.MainActivity}: java.lang.NullPointerException

How can I fix this?

Upvotes: 0

Views: 348

Answers (1)

Jitendra
Jitendra

Reputation: 1125

First find the listview by Id such as

lv = (ListView)findViewById(R.id.listview);

Upvotes: 3

Related Questions