Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.