0

In my android app, I have a navigation drawer menu and its populated with a string array. When i click the individual strings I want to open a new activity (both are fragment activities). This does not work as I thought it would. Any other ways suitable?

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    SelectItem(position);
}

public void SelectItem(int position) {
    listView.setItemChecked(position, true);

    Intent testIntent = new Intent(MainActivity.this, AnotherActivity.class);

    //for example:
    if (position == 2) {
        startActivity(testIntent);
    }
}

logcat error: http://pastebin.com/v8pbpC0S

this is the class "AnotherActivity" 's contents: http://pastebin.com/zEymwJNQ Judging by the logcat I believe the error occurs here.

1 Answers1

0

You have NullPointerException at line 33

com.ex.app.AnotherActivity.onCreate(AnotherActivity.java:33)

Looks like ListView reference is null.

Eugene Krivenja
  • 647
  • 8
  • 18
  • if you take a look at my second pastebin (obviously different lines because i dont have the import lines, etc) the list view is clearly initialized. –  Dec 01 '15 at 13:48
  • Are you referencing the right ID from your XML file like R.id.drawerList? because logcat is clear listview is null – Kenan Begić Dec 01 '15 at 14:34
  • `findViewById(R.id.drawerList)` can return `null` value. – Eugene Krivenja Dec 02 '15 at 11:02