java在我将数据从一个活动传递到另一个活动时获取空指针Exp
"questions": [
{
"number": 1,
"text": "How many principles are there for plant distribution ?",
"options": [
{
"number": 1,
"text": "2",
"mark": 0
},
{
"number": 2,
"text": "4",
"mark": 0
},
{
"number": 3,
"text": "8",
"mark": 1
},
{
"number": 4,
"text": "16",
"mark": 0
}
],
"isMultiChoice": null
},{
"number": 1,
"text": "How many principles are there for plant distribution ?",
"options": [
{
"number": 1,
"text": "2",
"mark": 0
},
{
"number": 2,
"text": "4",
"mark": 0
},
{
"number": 3,
"text": "8",
"mark": 1
},
{
"number": 4,
"text": "16",
"mark": 0
}
],
"isMultiChoice": null
}]
以下是我处理选项的方式
optionsList = questionsList.get(question).getOptions();
但我有一个错误:
java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:3507) at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3661) at 安卓.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at 安卓.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140) at 安卓.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100) at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:2232) at 安卓.os.Handler.dispatchMessage(Handler.java:107) at 安卓.os.Looper.loop(Looper.java:238) at 安卓.app.ActivityThread.main(ActivityThread.java:7824) at java.lang.reflect.Method.invoke(Native Method) at com.安卓.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:981) Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference
你能帮我吗
Intent intent = getIntent();
questionsList = intent.getParcelableArrayListExtra("questionsData");
通过这种方式,我正在处理问题列表。 我能阅读问题。但我看不懂答案。 你能帮我吗
# 1 楼答案
从第一次活动开始使用
在第二个活动中使用