Reputation: 237
Code on sender Activity
Intent intent = new Intent(this, ScrollingActivity.class);
intent.putExtra("KEY", 1);
startActivity(intent);
Code on receiver Activity
int a = getIntent().getExtras().getInt("KEY");
While trying this getting this error log
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
Can you help for fix it?
Upvotes: 0
Views: 2049
Reputation: 49976
Your error indicates that getIntent
returns null reference, you should check where you are calling getIntent - it should be called inside or after Actvity.onCreate
in Activity life cycle.
Upvotes: 2