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 a Self-Destructing Message Android App Retrieving and Viewing Messages Viewing Image Messages

Viewing Image Messages (null pointer). Self Destructing App

My android project has been going great so far. I do get a Null Pointer Exception on line 41 of MessageAdapter.java after completing the "Viewing Image Messages" lesson though. I've compared my code and project setup with the files from Team Treehouse and I see nothing that stands out in my code repository.

I'll debug to find out more about the Null Pointer for creating my view and post this here in case anyone else has similar issues. I think it might have something to do with my layout xml because line 41 in MessageAdapter.java is where the code shows the view based on the filetype in the message (image or video).

message_item.xml looks correct (same as treehouse files from lesson) MessageAdapter.java looks correct (same as treehouse files from lesson) All my imports are same as treehouse lesson

When I run my project on my android device (no emulator) I get the following in console:

02-16 19:24:35.336: E/AndroidRuntime(31891): FATAL EXCEPTION: main 02-16 19:24:35.336: E/AndroidRuntime(31891): java.lang.NullPointerException 02-16 19:24:35.336: E/AndroidRuntime(31891): at com.monigarr.snappyandroid.MessageAdapter.getView(MessageAdapter.java:41) 02-16 19:24:35.336: E/AndroidRuntime(31891): at android.widget.AbsListView.obtainView(AbsListView.java:2161) 02-16 19:24:35.336: E/AndroidRuntime(31891): at android.widget.ListView.measureHeightOfChildren(ListView.java:1247) 02-16 19:24:35.336: E/AndroidRuntime(31891): at android.widget.ListView.onMeasure(ListView.java:1159) 02-16 19:24:35.336: E/AndroidRuntime(31891): at android.view.View.measure(View.java:15848) 02-16 19:24:35.336: E/AndroidRuntime(31891): at android.widget.RelativeLayout.measureChild(RelativeLayout.java:698) 02-16 19:24:35.336: E/AndroidRuntime(31891): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:494)

1 Answer

I kept going forward with the lessons and see that line 36 was actually a problem. The lesson for Maintaining Scroll Position in a ListView helped me to figure that out and all is well with my awesome android project now :)