Skip to content Skip to sidebar Skip to footer

Udacity Sunshine App - Lesson 1 - Nullpointerexception When Trying To Display Mock Listview

I'm going through the Android dev training at udacity.com, following along with the implementation of the Sunshine app. I'm using Android Studio, latest version default installati

Solution 1:

Change:

mForeCastAdapter = newArrayAdapter<String>(
                getActivity(),
                R.layout.list_item_forecast,
                R.id.listview_forecast,
                weekForecast);

to:

mForeCastAdapter = newArrayAdapter<String>(
                getActivity(),
                R.layout.list_item_forecast,
                weekForecast);

The ID parameter in the constructor that you are using is supposed to be an ID of a TextView inside of your row layout. That is only needed if your row layout is more than a TextView, though. In your case:

  • the row layout is only a TextView, so you do not need to provide the ID

  • the ID you are providing is not for a TextView in your row layout, but rather for a ListView elsewhere

Solution 2:

If the above solution does not work for you, and you are testing on a physical device, check that the portrait and landscape layouts both have the ListView declared. AS may create both files for you, and NPE will occur if the ListView is added only to one and then you switch orientations during testing.

Post a Comment for "Udacity Sunshine App - Lesson 1 - Nullpointerexception When Trying To Display Mock Listview"