0

I really don't know what's wrong: I've made function, that moves user to AddNewQuestionClass

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

I'm also sending "sciezka" variable. Now, I'm getting this variable in 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);
    }
}

Unfortunately, something don't works:

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

This is #185 line (there is an error):

 sciezka_do_pliku_z_obrazem = bundle.getString("sciezka1");

What's wrong?

Piotrek
  • 10,919
  • 18
  • 73
  • 136
  • Try grabbing it from the extras, not the bundle. – JoxTraex Dec 10 '12 at 19:56
  • If you haven't solved this yet, can you print out the value before butting it into the intent extras and after retrieving from the bundle, so we can confirm that what's going in isn't null and what's coming out is? – gsgx Dec 16 '12 at 19:24

3 Answers3

1

Try this

getIntent().getStringExtra("sciezka1");

rather than bundle... I hope it will solve ur problem

Faizan
  • 3,512
  • 2
  • 18
  • 15
  • the same error :/ When I put this into try/catch, in logs I have this: 12-11 21:01:04.670: E/EO(19298): java.io.FileNotFoundException: No content provider: /storage/sdcard0/AAProgramDoNauki/uuu.png – Piotrek Dec 11 '12 at 20:04
1

It seems like your variable sciezka is null, so later in onResume() when bundle.getString('sciezka') the value of sciezka is empty thus throwing a null pointer exception.

Make sure sciezka is not empty, you can do a Log.i after

intent.putExtra("sciezka1", sciezka); to dump variable sciezka to confirm this.

francisOpt
  • 860
  • 1
  • 8
  • 15
0

It looks like the bundle you are trying to call method getString() on is null. That's the reason you're getting a Null Pointer Exception.

Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
sviro
  • 46
  • 2