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) Concurrency and Error Handling Configuring the Alert Dialog

I keep getting the error message on the emulator even though I've changed the longitude.

If you know this course this is the part where you change the latitude to see if the error message would work and it did. When I changed back though the message still comes up. What should I do? Here's the code.

public class MainActivity extends AppCompatActivity {

    public static final String TAG =MainActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String apiKey = "xxxxxxxxxxxxx";
        double latitude = 37.8267 ;
        double longitude =-122.4233;
        String forecastURL = "https://api.darksky.net/forecast/"+apiKey+"/"
                + latitude +" , "+ longitude+"";


        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(forecastURL)
                .build();
        //This is the request to get data from forecast.

        okhttp3.Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(okhttp3.Call call, IOException e) {

            }

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

                try {Log.v(TAG, response.body().string());

                    if (response.isSuccessful()) {

                    }

                else {
                       alertUserAboutError();
                    }


            }catch (IOException e){
                Log.e(TAG, "Exception caught", e);
            }
               Log.d(TAG, "Main UI code is running!");
            }

            });
        }
public class AlertDialogFragment extends DialogFragment {

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

Benjamin Young I've made a new question that is more relevant. The two errors i could find is {"code":400,"error":"The given location (or time) is invalid."} and java.io.FileNotFoundException here is the link to the new question.

1 Answer

What kind of error messages are you getting? I see several syntax errors. Check your spacing and then let me know what the code says.