Sunday, January 31, 2010

WILT: NullPointerException when calling startActivity

That’s such a beginner error but I have no shame posting about it because I AM a beginner with Android  :)

When trying to start a ListActivity from my main Activity, I kept on getting a NullPointerException. The code to launch my activity looked like this:

myActivityInstance.startActivity(new Intent(Intent.ACTION_VIEW));

Well, the problem was that I forgot to set the content view at the beginning of my launched activity. All I had to do was add this line at the beginning of my onCreate event handler:

setContentView(R.layout.tasks_list);

[Via http://benoit808.wordpress.com]

No comments:

Post a Comment