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 Android Lists and Adapters (2015) Acting on List Item Taps Wrapping Up

Stormy Weather App: Crashing & Context

Crashing: When the user starts up the app and no available network is detected, a Toast message is displayed. However, when the user taps on the Hourly or Weekly buttons, the app crashes. This issue can be easily fixed with a simple if statement to check if the network is available upon button tap, and if not, an else statement can execute a Toast message notifying the user about the lack of network connection.

    @OnClick (R.id.dailyButton)
    public void startDailyActivity(View view) {
        if (isNetworkAvailable()) {
            Intent intent = new Intent(this, DailyForecastActivity.class);
            intent.putExtra(DAILY_FORECAST, mForecast.getDailyForecast());
            startActivity(intent);
        }
        else {
            Toast.makeText(this, "Network is unavailable!", Toast.LENGTH_LONG).show();
        }
    }

    @OnClick (R.id.hourlyButton)
    public void startHourlyActivity(View view) {
        if (isNetworkAvailable()) {
            Intent intent = new Intent(this, HourlyForecastActivity.class);
            intent.putExtra(HOURLY_FORECAST, mForecast.getHourlyForecast());
            startActivity(intent);
        } else {
            Toast.makeText(this, "Network is unavailable!", Toast.LENGTH_LONG).show();
        }
    }

Context: There is a small discrepancy in ViewGroup's variable name in the HourViewHolder method located within the HourAdapter class. I believe this is due to varying Android Studio versions. Another member provided a solution.