我正在使用列表:
List<Float> subjects = Arrays.asList(0f,0f,0f,0f,0f,0f);
List<Float> question9 = Arrays.asList(0f,0f);
我想把它发送到另一个使用Intent的活动:
Intent iQuizz= new Intent(BachelorsResults.this, Results.class);
iQuizz.putExtra(BACHELOR, spinner.getSelectedItem().toString());
iQuizz.putExtra(QUESTION_9, question9.toArray());
iQuizz.putExtra(FAILED_SUBJECTS, subjects.toArray());
BachelorsResults.this.startActivity(iQuizz);
在另一项活动中,我正在尝试接收浮动值:
Bundle extras = getIntent().getExtras();
float[] q9= extras.getFloatArray(QUESTION_9);
float[] fSubjects= extras.getFloatArray(FAILED_SUBJECTS);
但是,一旦我开始第二次活动,它就会启动此例外:
3-05 15:30:28.221 24640-24640/citrapp.exatec E/AndroidRuntime: FATAL EXCEPTION: main
Process: citrapp.exatec, PID: 24640
java.lang.RuntimeException: Unable to start activity ComponentInfo{citrapp.exatec/citrapp.exatec.Resultados}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at citrapp.exatec.Resultados.onCreate(Resultados.java:85)
at android.app.Activity.performCreate(Activity.java:6259)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
当我将它们传递给另一个活动时,float数组变为空值,因为我在第一个活动中测试extras.getFloatArray并显示内容,但在第二个活动中它没有。如果有人可以帮助我会很棒.. 谢谢!
答案 0 :(得分:0)
尝试将getIntent().getExtras()
替换为getIntent().getFloatArrayExtra()
。