Starting New Activity Using Intent. Npe At Android.content.contextwrapper.getpackagename
Solution 1:
My bet here is that you are trying to start an activity from an activity that is not fully initialized.
Make sure FirstActivity.onCreate has been called before starting another activity.
Solution 2:
The error looks like the context provided to the Intent constructor is null.
The code should look more like:
publicvoidstartLevelEnd(Context context){
Intent myIntent = newIntent(context, LevelEndPanel.class);
context.startActivity(myIntent);
}
Be sure that you call startLevelEnd
from an activity using this call
startLevelEnd(this)
If startLevelEnd
is located in the same Activity class that is calling it, simplify it:
publicvoidstartLevelEnd(){
Intent myIntent = new Intent(this, LevelEndPanel.class);
startActivity(myIntent);
}
Solution 3:
I'm fairly sure that you have to use a context for the first parameter in an Intent, and since you have a context as a parameter on your startLevelEnd method, you can try
Intent myIntent = newIntent (context, LevelEndPanel.class);
context.startActivity(myIntent);
I think you're getting the NullPointerException because your class can't see the FirstActivity. But it depends on where the startLevelEnd method is. And since you don't say where it is, try it!
Post a Comment for "Starting New Activity Using Intent. Npe At Android.content.contextwrapper.getpackagename"