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

Running app crashes when I click the 1st button

App crashes when I select the 1st button after the 1st step "Stop and Investigate". the 2nd button runs perfect but when I do the First button the app crashes. Any hint at how to solve it?. Thanks below crash report :

1-14 15:10:22.320 19141-19141/com.example.android.interactivestory E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.android.interactivestory, PID: 19141 java.lang.NullPointerException: Attempt to invoke virtual method 'int com.example.android.interactivestory.model.Page.getImageId()' on a null object reference at com.example.android.interactivestory.ui.StoryActivity.loadPage(StoryActivity.java:60) at com.example.android.interactivestory.ui.StoryActivity.access$100(StoryActivity.java:18) at com.example.android.interactivestory.ui.StoryActivity$2.onClick(StoryActivity.java:89) at android.view.View.performClick(View.java:4756) at android.view.View$PerformClick.run(View.java:19749) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

2 Answers

It looks like null was passed into the method getImageId(). Can you please show your code for the Page and StoryActivity classes? That should help further identify the error.

Thanks for your response. I already fixed. What happen is that I didn't the copy the data for # 1 in the Story Activity. now it works perfect.

I'm glad you were able to fix it, good luck with the rest of the course!