Android - Two Actvities can't get Bundle Extras out of Nine

49 Views Asked by At

So I have 9 activities that started out as copy and pastes of each other. As far as I can tell they really only differ in the number of check boxes and text fields on them. Two of the activities can't receive Bundle Extras and it has me stumped. I can move freely between the 7 working activities but the last two wont receive Bundle Extras from any of the other activities.

The only information that is being passed about is one int.

Sender Example

myIntent = new Intent(getBaseContext(), PostSession.class);
output.putInt("flightId", mFlightInfoId);
startActivity(myIntent);
overridePendingTransition(0, 0);

Receiver Example from one of the non-working activities

Bundle extras = getIntent().getExtras();
mFlightInfoId = extras.getInt("flightId");

Error Message

java.lang.RuntimeException: Unable to start activity ComponentInfo{project.xyz.logging/project.xyz.logging.PostSession}: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.os.Bundle.getInt(java.lang.String)' on a null object reference

2

There are 2 best solutions below

0
Mytheral On BEST ANSWER

Just like @Napster said I forgot to put the output bundle into the Intent

0
John Le On

Have you tried to use the below code. I recommend you to have a look on this tutorial:

mFlightInfoId = getIntent().getIntExtra("flightId");