0

我真的不知道出了什么问题:我制作了函数,将用户移动到 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”变量。现在,我在 AddNewQuestionClass 中得到了这个变量:

@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");

怎么了?

4

3 回答 3

1

尝试这个

getIntent().getStringExtra("sciezka1");

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

于 2012-12-10T19:56:57.653 回答
1

看起来你的变量sciezka是空的,所以稍后onResume()sciezkabundle.getString('sciezka')的值为空时会抛出空指针异常。

确保sciezka不是空的,你可以做一个Log.iafter

intent.putExtra("sciezka1", sciezka);转储变量sciezka以确认这一点。

于 2012-12-10T20:01:09.817 回答
0

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

于 2012-12-10T20:00:50.487 回答