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 Retrieving Messages

Jeremy Broutin
Jeremy Broutin
1,951 Points

NullPointerException on navigation back button

Hello team,

When testing the app at this stage of the learning path, it works fine (aka I got the list of messages in my inbox) apart from the use of the navigation back button which causes the app to crash. Looking at the logcat, I can see that I get a NullPointerException. Reading stackoverflow, a member mentions that it's probably due to the setListAdapter: "You should look at where you're calling setListAdapter and where you're initializing the List that you pass into it. You need to ensure that your List has been initialized first."

Could you please help to correct this bug?

Thanks a lot :)

Andrew West
Andrew West
3,245 Points

Jeremy, is there a stack trace you can show us? The stack trace can tell you where in your program something is going wrong.

The stack trace might look something like this:

java.lang.NullPointerException
at com.j.infographx.ListRSSItemsActivity$1.onItemClick(ListRSSItemsActivity.java:74)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1287)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3078)
at android.widget.AbsListView$1.run(AbsListView.java:4161)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)

1 Answer

Hi Jeremy,

Where are you getting the NullPointerException - Logcat should tell you what line that's happening at and you can see what line that is.

It might be wise running the code in the debugger and putting some breakpoints around to track down where this is happening but let's start with Logcat.

Steve.