Android ndk 代码给出空指针异常错误

Android ndk 代码给出空指针异常错误,android-ndk,Android Ndk,我正在从其他活动接收值,并使用这些值尝试从数据库中获取数据,但会发生NullPointerException final Bundle bundle=this.getIntent().getExtras(); String topic=bundle.getString("topic"); String subtopic=bundle.getString("subtopic"); 我的数据库查询是 public Cursor getAll() { return (ge

我正在从其他活动接收值,并使用这些值尝试从数据库中获取数据,但会发生NullPointerException

    final Bundle bundle=this.getIntent().getExtras();
 String topic=bundle.getString("topic");
 String subtopic=bundle.getString("subtopic");
我的数据库查询是

public Cursor getAll() {
        return (getReadableDatabase().query("Q_A", new String[] { "_id",
                "Question","QLevel", "TopicId", "SubTopicId" }, "TopicId=? AND SubTopicId=?",
                new String[] { topic + "", subtopic + "" }, null, null,
                null));
    }

如果mu GUSE是正确的,那么您将从上一个活动中以整数形式发送意图数据类型,并在当前活动中以字符串形式接收

确保发送字符串类型和获取字符串类型

将代码更改为:

final Bundle bundle=this.getIntent().getExtras();
String topic=bundle.getInt("topic");
String subtopic=bundle.getInt("subtopic");

可能getReadableDatabase返回null。你从哪里得到的?ourCursor=helper.getAll;这里我调用了我的getAll方法,我想问题出在Bundle代码中,当我从下面给出的代码中替换该代码时,它会运行ok final String topic=1;最终字符串子主题=3;