我真的不知道出了什么问题:我制作了函数,将用户移动到 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");
怎么了?