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) Working with JSON Exploring the Data

Aldrin Cabuniag
Aldrin Cabuniag
3,783 Points

Unreachable Statement

Attempting to follow along the Basic Android Dev course (Weather App) and everything is going soundly except for an error: "unreachable statement".

There is a red squiggly line on this entire line and I am unsure how to fix this. Any help would be appreciated- thanks :).

Context context = getActivity();

Here is a larger view of that code:

public class AlertDialogFragment extends DialogFragment {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    return super.onCreateDialog(savedInstanceState);
    Context context = getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context)
            .setTitle(context.getString(R.string.error_title))
            .setMessage(context.getString(R.string.error_message))
            .setPositiveButton(R.string.error_ok_button_text2, null);
    AlertDialog dialog = builder.create();
    return dialog;
}

}

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Aldrin - The problem is that in the onCreateDialog() method the first line of code is a return statement so you can never reach the lines of code that follow. You need to remove that line.