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 Weather App (2015) Hooking Up the Model to the View Plugging in the Data

Luv Kapur
Luv Kapur
124 Points

updateDisplay() gives a nullpointer exception even though the Weather object is populated with json data from the api ca

ShowWeather() works with all weather data but updateWeather() doesn't

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) {

        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            try {

                jsonData = response.body().string();
                // log the response
                Log.v("Network Response", response.body().string());
                if (response.isSuccessful()) {
                    setCurrentWeather();
                    setWeeklyWeather();
                    showWeather();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            updateWeather();
                        }
                    });

                } else {
                    network.alertError();
                }
            } catch (IOException | JSONException e) {
                Log.e("Network Response", "Exception Caught", e);
            }

private void updateWeather() { temperature.setText(String.valueOf(currentWeather.getTemperature())); }

private void showWeather() {
   Log.v("Weather", currentWeather.spit());
}

1 Answer

This does not work.