Search code examples
javaandroidandroid-intentandroid-fragmentactivity

Android App - New Activity not opening


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.


Solution

  • You have NullPointerException at line 33

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

    Looks like ListView reference is null.