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 Concurrency and Error Handling Making Our Code Asynchronous

The data is not displaying in the logcat and it is showing some random erros

String apiKey = "0123456789abcdef9876543210fedcba";

    double latitude = 42.3601;
    double longitude = -71.0589;

    String forecastURL =  "https://api.darksky.net/forecast/"
            + apiKey + "/" + latitude + "," + longitude;// we will have to refactor it bcoz u want to avoid harcoded text..

      OkHttpClient client = new OkHttpClient();

      //build a request to dark sky api
    Request request = new Request.Builder().url(forecastURL).build();

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

        }

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

                //write an if block to know whether the resonse is successful or not
                if(response.isSuccessful()){
                    Log.v(TAG,response.body().string()); //printing entire response to the log console..
                }
            } catch (IOException e) {
                Log.e(TAG,"IO exception caught",e);
            }
        }
    });

////////////////errors/////////////////////// 2019-03-08 12:17:18.420 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 16 2019-03-08 12:17:21.180 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 4 2019-03-08 12:17:29.180 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 16 2019-03-08 12:17:29.183 26057-26080/? E/radish: radish_send_nd_packet sent 72 bytes 2019-03-08 12:17:32.300 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 4 2019-03-08 12:17:33.736 26057-26080/? E/radish: radish_send_nd_packet sent 72 bytes 2019-03-08 12:17:37.320 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 16 2019-03-08 12:17:38.740 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 16 2019-03-08 12:17:38.743 26057-26080/? E/radish: radish_send_nd_packet sent 72 bytes 2019-03-08 12:17:38.985 10751-10751/? E/n: getNetworkOperatorForSubscription [int] 2019-03-08 12:17:46.700 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 4 2019-03-08 12:17:49.501 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 4 2019-03-08 12:17:53.430 714-714/? E/cnss-daemon: Stale or unreachable neighbors, ndm state: 16

Thanks for your time and help..

1 Answer

Hi Vams.

String apiKey = "0123456789abcdef9876543210fedcba"; is not a valid API key for the DarkSky API. If I remember well, it is a mock key used in their documentation.

You need to register and apply for an API key on their website.

Hope that helps :)

Thnank you i had solved it thnaks for your answer...

You're welcome. I'm glad you sorted it out :)