+ 1

Resolve Java nullPointer exception

In my app i use Intent for start an activity, but the exception say this: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.content. Intent.setClass(android.content.Context, java.lang.Class)' on a null object reference and this is the code: Intent i = new Intent(getApplicationContext(), MyActivity.class); startActivity(i); How can i do?

8th Jan 2018, 4:54 PM
Stefano Trinca
Stefano Trinca - avatar
1 Answer
+ 10
Try Intent i = new Intent(CurrentActivity.this, MyActivity.class); startActivity(i); Where current Activity is the Activity you are trying to move from
9th Jan 2018, 7:56 PM
David Akhihiero
David Akhihiero - avatar