Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android应用程序-新活动未打开_Java_Android_Android Intent_Android Fragmentactivity - Fatal编程技术网

Java Android应用程序-新活动未打开

Java Android应用程序-新活动未打开,java,android,android-intent,android-fragmentactivity,Java,Android,Android Intent,Android Fragmentactivity,在我的android应用程序中,我有一个导航抽屉菜单,其中填充了一个字符串数组。当我单击单个字符串时,我想打开一个新活动(两者都是片段活动)。这并不像我想的那样有效。还有其他合适的方式吗 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SelectItem(position); } public void SelectItem(int position) {

在我的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);
    }
}
public void onItemClick(AdapterView父视图、视图视图、整型位置、长id){
选择项目(位置);
}
public void SelectItem(内部位置){
setItemChecked(位置,true);
Intent testIntent=新的Intent(MainActivity.this,AnotherActivity.class);
//例如:
如果(位置==2){
开始触觉(睾丸);
}
}
logcat错误:

这是“AnotherActivity”类的内容:
根据logcat判断,我相信错误发生在这里。

第33行有
NullPointerException

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

看起来
ListView
引用为
null

是否向清单文件中添加了其他活动?首先删除行
如果(位置==2)
@activesince93我将把它更改为case语句。这只是一个测试。你能调试吗?我的意思是你试过设置断点。这很有用吗?@Raghavendra我用logcat错误的粘贴库更新了我的原始帖子如果你看一下我的第二个粘贴库(显然是不同的行,因为我没有导入行等),列表视图被清晰地初始化了。你是否引用了XML文件中的正确ID,比如R.ID.drawerList?因为logcat是清除的,所以listview是null
findViewById(R.id.drawerList)
可以返回
null
值。