Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build an Interactive Story App (Retired) Finishing the User Interface Loading the First Page

I get a java.lang.NullPointerException on mChoice2.setText(page.getChoice2().getText()); removing it makes it work

I get this error Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.android.interactivestory.model.Choice.getText()' on a null object reference at com.example.android.interactivestory.ui.StoryActivity.loadPage(StoryActivity.java:61) at com.example.android.interactivestory.ui.StoryActivity.onCreate(StoryActivity.java:49)

My GIT Repo is https://github.com/iandjx/InteractiveStory.

Thanks!

Further investigation showed that when page object is created with mStory.getpage(0) in line 52 of StoryActivity.java. The debugger shows that mChoice2 is null. This may be the one causing the NullPointerException but I dont see any problem with my code.

1 Answer

Ok I made a stupid mistake. Apparently line 14 in Page.java. I duplicated mChoice1 instead of mChoice 2. See diff in my commits :) Everything is now working.

I love the debugger!