在我的android应用程序中,我有一个导航抽屉菜单,它填充了一个字符串数组。当我单击各个字符串时,我想打开一个新的活动(两者都是片段活动)。这不会像我想象的那样奏效。还有其他合适的方式吗?
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错误:http://pastebin.com/v8pbpC0S
这是类"AnotherActivity"的内容:http://pastebin.com/zEymwJNQ根据日志判断,我认为错误发生在这里。
在第33行有NullPointerException
com.ex.app.AnotherActivity.onCreate(AnotherActivity.java:33)
看起来ListView
引用是null
。