我正在one activity
发送数组,并在other activity
中获取该数组。
这是我的代码(接收方)
Bundle Extras = getIntent().getExtras();
if(Extras != null)
{
reports = getIntent().getStringArrayExtra("reports");
System.out.println("Size() "+reports.length);
}
但我得到以下错误
07-16 18:15:27.628: W/Bundle(718): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-16 18:15:27.628: W/Bundle(718): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 18:15:27.628: W/Bundle(718): at android.os.Looper.loop(Looper.java:130)
07-16 18:15:27.628: W/Bundle(718): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-16 18:15:27.628: W/Bundle(718): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 18:15:27.628: W/Bundle(718): at java.lang.reflect.Method.invoke(Method.java:507)
07-16 18:15:27.628: W/Bundle(718): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-16 18:15:27.628: W/Bundle(718): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-16 18:15:27.628: W/Bundle(718): at dalvik.system.NativeStart.main(Native Method)
07-16 18:15:27.658: W/System.err(718): java.lang.NullPointerException
07-16 18:15:27.658: W/System.err(718): at com.mythrii.timeapp.EditReports.onCreate(EditReports.java:41)
07-16 18:15:27.698: W/System.err(718): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 18:15:27.698: W/System.err(718): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-16 18:15:27.698: W/System.err(718): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-16 18:15:27.698: W/System.err(718): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-16 18:15:27.698: W/System.err(718): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-16 18:15:27.698: W/System.err(718): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 18:15:27.698: W/System.err(718): at android.os.Looper.loop(Looper.java:130)
07-16 18:15:27.698: W/System.err(718): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-16 18:15:27.698: W/System.err(718): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 18:15:27.698: W/System.err(718): at java.lang.reflect.Method.invoke(Method.java:507)
07-16 18:15:27.698: W/System.err(718): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-16 18:15:27.698: W/System.err(718): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-16 18:15:27.729: W/System.err(718): at dalvik.system.NativeStart.main(Native Method)
请有人帮帮我。
答案 0 :(得分:0)
Bundle Extras = getIntent().getExtras();
if(Extras != null)
{
reports = Extras.getStringArrayExtra("reports");
System.out.println("Size() "+reports.length);
}
答案 1 :(得分:0)
也许你没有从额外获得任何数组(使用键报告)。您需要检查报告对象是否也是null
。
Bundle Extras = getIntent().getExtras();
if(Extras != null)
{
reports = getIntent().getStringArrayExtra("reports");
if(reports != null)
System.out.println("Size() "+reports.length);
}
答案 2 :(得分:0)