Search code examples
javaandroidandroid-intentnullpointerexceptionbundle

Problem receiving data through Intent on Android


It's better to post pictures to show what exactly is going on, okay? The first image shows an object of the Intent class called senderIntent, which will send it to a class called "Resultado". The senderIntent (which is an object of the Intent class) sends the value of the variable email, to another variable also called email:

enter image description here

In the next image, it shows that I created an object of the Intent class called receiverIntent:

enter image description here

Then I created an object of the Bundle class that receives the receiverIntent's getextras() method. The problem is that the NullPointer Exception error is happening in the line of code: Bundle receiverBundle = receiverIntent.getExtras();

Please what to do to fix it?


Solution

  • Generally speaking, do not call Activity methods from a field initializer. Move your getIntent() and getExtras() calls to be inside of onCreate(), after the call to super.onCreate().