Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 :)