RuntimeException:无法恢复活动。意图得到额外的东西

时间:2012-12-10 19:49:30

标签: android android-intent nullpointerexception bundle runtimeexception

我真的不知道出了什么问题: 我已经创建了函数,将用户移动到AddNewQuestionClass

//function is in Activity Class
public void wroc(String sciezka){
    Intent intent = new Intent(this, AddNewQuestion.class);
    intent.putExtra("sciezka1", sciezka);
    startActivity(intent);
}

我也发送“sciezka”变量。现在,我在AddNewQuesionClass中获取此变量:

@Override
protected void onResume() {
    super.onResume();
    Bundle bundle = getIntent().getExtras();
    sciezka_do_pliku_z_obrazem = bundle.getString("sciezka1");
    Uri myUri = Uri.parse(sciezka_do_pliku_z_obrazem);
    try {

        Bitmap jakisobraz = MediaStore.Images.Media.getBitmap(this.getContentResolver(), myUri);
        obrazekdoedycji.setImageBitmap(jakisobraz);
    }
    catch(Exception e){
        Log.e("EO", " " + e);
    }
}

不幸的是,有些东西不起作用:

12-10 20:21:12.213: E/AndroidRuntime(9173): FATAL EXCEPTION: main
12-10 20:21:12.213: E/AndroidRuntime(9173): java.lang.RuntimeException: Unable to resume activity {app.piotrek.learning/app.piotrek.learning.AddNewQuestion}: java.lang.NullPointerException
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2701)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2729)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2215)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.ActivityThread.access$600(ActivityThread.java:142)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.os.Looper.loop(Looper.java:137)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.ActivityThread.main(ActivityThread.java:4931)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at java.lang.reflect.Method.invokeNative(Native Method)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at java.lang.reflect.Method.invoke(Method.java:511)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at dalvik.system.NativeStart.main(Native Method)
12-10 20:21:12.213: E/AndroidRuntime(9173): Caused by: java.lang.NullPointerException
12-10 20:21:12.213: E/AndroidRuntime(9173):     at app.piotrek.learning.AddNewQuestion.onResume(AddNewQuestion.java:185)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.Activity.performResume(Activity.java:5082)
12-10 20:21:12.213: E/AndroidRuntime(9173):     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2691)
12-10 20:21:12.213: E/AndroidRuntime(9173):     ... 12 more

这是#185行(有错误):

 sciezka_do_pliku_z_obrazem = bundle.getString("sciezka1");

怎么了?

3 个答案:

答案 0 :(得分:1)

试试这个

getIntent().getStringExtra("sciezka1");

而不是捆绑...... 我希望它能解决你的问题

答案 1 :(得分:1)

您的变量 sciezka 似乎为空,因此稍后onResume() bundle.getString('sciezka') sciezka 的值为空,因此抛出null指针异常。

确保 sciezka 不为空,您可以在<{p>}后执行Log.i

intent.putExtra("sciezka1", sciezka);转储变量 sciezka 以确认此信息。

答案 2 :(得分:0)

您尝试调用方法getString()的包看起来像是null。这就是你获得空指针异常的原因。