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 Making Our Code Asynchronous

Niyamat Almass
Niyamat Almass
8,176 Points

Need help!

I make my code asynchronous but in the log I see

Log.java
08-07 06:30:08.319    1506-1506/com.almass.niyamat.stormy D/dalvikvm Late-enabling CheckJNI
08-07 06:30:08.635    1506-1511/com.almass.niyamat.stormy E/jdwp Failed sending reply to debugger: Broken pipe
08-07 06:30:08.635    1506-1511/com.almass.niyamat.stormy D/dalvikvm Debugger has detached; object registry had 1 entries
08-07 06:30:09.051    1506-1508/com.almass.niyamat.stormy D/dalvikvm GC_CONCURRENT freed 45K, 3% free 3854K/3968K, paused 1ms+0ms, total 3ms
08-07 06:30:09.923    1506-1506/com.almass.niyamat.stormy D/MainActivity Main UI code is running
08-07 06:30:10.079    1506-1506/com.almass.niyamat.stormy D/libEGL loaded /system/lib/egl/libEGL_genymotion.so
08-07 06:30:10.079    1506-1506/com.almass.niyamat.stormy D/ HostConnection::get() New Host Connection established 0xb8831260, tid 1506
08-07 06:30:10.719    1506-1506/com.almass.niyamat.stormy D/libEGL loaded /system/lib/egl/libGLESv1_CM_genymotion.so
08-07 06:30:10.719    1506-1506/com.almass.niyamat.stormy D/libEGL loaded /system/lib/egl/libGLESv2_genymotion.so
08-07 06:30:13.707    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy I/dalvikvm Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to resolve static method 1849: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy D/dalvikvm VFY: replacing opcode 0x71 at 0x000a
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy I/dalvikvm Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to resolve static method 1848: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy D/dalvikvm VFY: replacing opcode 0x71 at 0x000a
08-07 06:30:13.715    1506-1542/com.almass.niyamat.stormy D/dalvikvm GC_FOR_ALLOC freed 464K, 12% free 3903K/4428K, paused 5ms, total 5ms
08-07 06:30:14.271    1506-1542/com.almass.niyamat.stormy V/MainActivity {"code":400,"error":"The given location is invalid."}
08-07 06:30:18.315    1506-1506/com.almass.niyamat.stormy W/EGL_genymotion eglSurfaceAttrib not implemented
08-07 06:30:18.327    1506-1506/com.almass.niyamat.stormy E/OpenGLRenderer Getting MAX_TEXTURE_SIZE from GradienCache
08-07 06:30:18.327    1506-1506/com.almass.niyamat.stormy E/OpenGLRenderer MAX_TEXTURE_SIZE: 16384
08-07 06:30:18.391    1506-1506/com.almass.niyamat.stormy E/OpenGLRenderer Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
08-07 06:30:18.399    1506-1506/com.almass.niyamat.stormy E/OpenGLRenderer MAX_TEXTURE_SIZE: 16384
08-07 06:30:18.399    1506-1506/com.almass.niyamat.stormy D/OpenGLRenderer Enabling debug mode 0
08-07 06:30:18.403    1506-1506/com.almass.niyamat.stormy D/dalvikvm GC_FOR_ALLOC freed 44K, 12% free 3924K/4428K, paused 2ms, total 2ms
08-07 06:30:18.403    1506-1506/com.almass.niyamat.stormy I/dalvikvm-heap Grow heap (frag case) to 4.104MB for 225516-byte allocation
08-07 06:30:18.407    1506-1515/com.almass.niyamat.stormy D/dalvikvm GC_FOR_ALLOC freed 1K, 11% free 4143K/4652K, paused 4ms, total 4ms
08-07 06:30:18.427    1506-1506/com.almass.niyamat.stormy D/dalvikvm GC_FOR_ALLOC freed 1K, 11% free 4144K/4652K, paused 3ms, total 3ms
08-07 06:30:18.443    1506-1506/com.almass.niyamat.stormy I/dalvikvm-heap Grow heap (frag case) to 6.523MB for 2536932-byte allocation
08-07 06:30:18.447    1506-1515/com.almass.niyamat.stormy D/dalvikvm GC_FOR_ALLOC freed <1K, 8% free 6621K/7132K, paused 4ms, total 4ms
08-07 06:30:21.331    1506-1506/com.almass.niyamat.stormy W/EGL_genymotion eglSurfaceAttrib not implemented
08-07 06:36:52.030    1615-1615/com.almass.niyamat.stormy D/dalvikvm Late-enabling CheckJNI
08-07 06:36:52.066    1615-1619/com.almass.niyamat.stormy E/jdwp Failed sending reply to debugger: Broken pipe
08-07 06:36:52.066    1615-1619/com.almass.niyamat.stormy D/dalvikvm Debugger has detached; object registry had 1 entries
08-07 06:36:52.078    1615-1617/com.almass.niyamat.stormy D/dalvikvm GC_CONCURRENT freed 142K, 6% free 3778K/3984K, paused 1ms+0ms, total 3ms
08-07 06:36:52.118    1615-1615/com.almass.niyamat.stormy D/MainActivity Main UI code is running
08-07 06:36:53.862    1615-1615/com.almass.niyamat.stormy D/libEGL loaded /system/lib/egl/libEGL_genymotion.so
08-07 06:36:53.862    1615-1615/com.almass.niyamat.stormy D/ HostConnection::get() New Host Connection established 0xb8831620, tid 1615
08-07 06:37:00.518    1615-1615/com.almass.niyamat.stormy D/libEGL loaded /system/lib/egl/libGLESv1_CM_genymotion.so
08-07 06:37:00.518    1615-1615/com.almass.niyamat.stormy D/libEGL loaded /system/lib/egl/libGLESv2_genymotion.so
08-07 06:37:06.157    1615-1628/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
08-07 06:37:06.157    1615-1628/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
08-07 06:37:06.157    1615-1628/com.almass.niyamat.stormy I/dalvikvm Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
08-07 06:37:06.157    1615-1628/com.almass.niyamat.stormy W/dalvikvm VFY: unable to resolve static method 1849: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
08-07 06:37:06.157    1615-1628/com.almass.niyamat.stormy D/dalvikvm VFY: replacing opcode 0x71 at 0x000a
08-07 06:37:06.161    1615-1628/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
08-07 06:37:06.161    1615-1628/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
08-07 06:37:06.161    1615-1628/com.almass.niyamat.stormy I/dalvikvm Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
08-07 06:37:06.161    1615-1628/com.almass.niyamat.stormy W/dalvikvm VFY: unable to resolve static method 1848: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;
08-07 06:37:06.161    1615-1628/com.almass.niyamat.stormy D/dalvikvm VFY: replacing opcode 0x71 at 0x000a
08-07 06:37:07.357    1615-1628/com.almass.niyamat.stormy D/dalvikvm GC_FOR_ALLOC freed 385K, 11% free 3907K/4352K, paused 8ms, total 8ms
08-07 06:37:07.365    1615-1628/com.almass.niyamat.stormy V/MainActivity {"latitude":37.8267,"longitude":-122.423,"timezone":"America/Los_Angeles","offset":-7,"currently":{"time":1438929426,"summary":"Mostly Cloudy","icon":"partly-cloudy-night","nearestStormDistance":2,"nearestStormBearing":47,"precipIntensity":0,"precipProbability":0,"temperature":60.74,"apparentTemperature":60.74,"dewPoint":55.3,"humidity":0.82,"windSpeed":9.02,"windBearing":240,"visibility":6.58,"cloudCover":0.75,"pressure":1010.25,"ozone":318.82},"minutely":{"summary":"Mostly cloudy for the hour.","icon":"partly-cloudy-night","data":[{"time":1438929420,"precipIntensity":0,"precipProbability":0},{"time":1438929480,"precipIntensity":0,"precipProbability":0},{"time":1438929540,"precipIntensity":0,"precipProbability":0},{"time":1438929600,"precipIntensity":0,"precipProbability":0},{"time":1438929660,"precipIntensity":0,"precipProbability":0},{"time":1438929720,"precipIntensity":0,"precipProbability":0},{"time":1438929780,"precipIntensity":0,"precipProbability":0},{"time":1438929840,"precipIntensity":0,"precipProbability":0},{"time":1438929900,"precipIntensity":0.0028,"precipIntensityError":0.0011,"precipProbability":0.02,"precipType":"rain"},{"time":1438929960,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.03,"precipType":"rain"},{"time":1438930020,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.05,"precipType":"rain"},{"time":1438930080,"precipIntensity":0.0029,"precipIntensityError":0.0012,"precipProbability":0.05,"precipType":"rain"},{"time":1438930140,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.05,"precipType":"rain"},{"time":1438930200,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.03,"precipType":"rain"},{"time":1438930260,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.02,"precipType":"rain"},{"time":1438930320,"precipIntensity":0.0028,"precipIntensityError":0.0011,"precipProbability":0.02,"precipType":"rain"},{"time":1438930380,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.01,"precipType":"rain"},{"time":1438930440,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.01,"precipType":"rain"},{"time":1438930500,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.01,"precipType":"rain"},{"time":1438930560,"precipIntensity":0.0029,"precipIntensityError":0.0011,"precipProbability":0.01,"precipType":"rain"},{"time":1438930620,"precipIntensity":0.0029,"precipIntensityError":0.0012,"precipProbability":0.01,"precipType":"rain"},{"time":1438930680,"precipIntensity":0,"precipProbability":0},{"time":1438930740,"precipIntensity":0,"precipProbability":0},{"time":1438930800,"precipIntensity":0,"precipProbability":0},{"time":1438930860,"precipIntensity":0,"precipProbability":0},{"time":1438930920,"precipIntensity":0,"precipProbability":0},{"time":1438930980,"precipIntensity":0,"precipProbability":0},{"time":1438931040,"precipIntensity":0,"precipProbability":0},{"time":1438931100,"precipIntensity":0,"precipProbability":0},{"time":1438931160,"precipIntensity":0,"precipProbability":0},{"time":1438931220,"precipIntensity":0,"precipProbability":0},{"time":1438931280,"precipIntensity":0.0031,"precipIntensityError":0.0014,"precipProbability":0.01,"precipType":"rain"},{"time":1438931340,"precipIntensity":0.0034,"precipIntensityError":0.0013,"precipProbability":0.01,"precipType":"rain"},{"time":1438931400,"precipIntensity":0.0034,"precipIntensityError":0.0013,"precipProbability":0.01,"precipType":"rain"},{"time":1438931460,"precipIntensity":0,"precipProbability":0},{"time":1438931520,"precipIntensity":0,"precipProbability":0},{"time":1438931580,"precipIntensity":0,"precipProbability":0},{"time":1438931640,"precipIntensity":0,"precipProbability":0},{"time":1438931700,"precipIntensity":0,"precipProbability":0},{"time":1438931760,"precipIntensity":0,"precipProbability":0},{"time":1438931820,"precipIntensity":0,"precipProbability":0},{"time":1438931880,"precipIntensity":0.0036,"precipI
08-07 06:37:11.581    1615-1615/com.almass.niyamat.stormy W/EGL_genymotion eglSurfaceAttrib not implemented
08-07 06:37:11.585    1615-1615/com.almass.niyamat.stormy E/OpenGLRenderer Getting MAX_TEXTURE_SIZE from GradienCache
08-07 06:37:11.589    1615-1615/com.almass.niyamat.stormy E/OpenGLRenderer MAX_TEXTURE_SIZE: 16384
08-07 06:37:12.021    1615-1615/com.almass.niyamat.stormy E/OpenGLRenderer Getting MAX_TEXTURE_SIZE from Caches::initConstraints()
08-07 06:37:12.025    1615-1615/com.almass.niyamat.stormy E/OpenGLRenderer MAX_TEXTURE_SIZE: 16384
08-07 06:37:12.025    1615-1615/com.almass.niyamat.stormy D/OpenGLRenderer Enabling debug mode 0
08-07 06:37:12.797    1615-1615/com.almass.niyamat.stormy D/dalvikvm GC_FOR_ALLOC freed 166K, 12% free 3938K/4472K, paused 6ms, total 7ms

But in the video Ben has different log in json. My Main Activity code is

MainActivity.java
package com.almass.niyamat.stormy;

import android.app.Activity;
import android.app.DownloadManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.IOException;


public class MainActivity extends Activity {
    public static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String apiKey = "b4de63a98386f7e128deaa126a3e23dd";
        double latitude = 37.8267;
        double longitude = -122.423;
        String forecastUrl = "https://api.forecast.io/forecast/" + apiKey + "/" + latitude + "," + longitude;


        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(forecastUrl)
                .build();

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

            }

            @Override
            public void onResponse(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");

    }

    private void alertUserAboutError() {
        AlertDialogFragment dialog = new AlertDialogFragment();
        dialog.show(getFragmentManager(), "error");
    }

}

What's wrong in my code why I don't see the weather forcast json file in logcat?

3 Answers

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hi Niyamat,

In the logcat you posted, there looks like to be your json response. It's the 8th line from the bottom.

{"latitude":37.8267,"longitude":-122.423,"timezone":"America/Los_Angeles","offset":-7,"currently":{..... and so on

I hope this helps, if not let me know.

Niyamat Almass
Niyamat Almass
8,176 Points

I actually confused because I don't find the json file.But I now I find the json file. Jon Kussmann Thank you so much for your help to find the json file. But in the log there are many problem, like that :

log.java
0:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to resolve static method 1849: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy D/dalvikvm VFY: replacing opcode 0x71 at 0x000a
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy I/dalvikvm Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source
08-07 06:30:13.711    1506-1542/com.almass.niyamat.stormy W/dalvikvm VFY: unable to resolve static method 1848: Ljava/nio/file/Files;.newInputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/InputStream;

What is that? Can I just ignore them? Thank you.

Niyamat,

Great work so far. I believe your issue is that the JSON data has been returned but you are not capturing it or logging it to the Log.? logfile. In your "try" block of the "onResponse" method add

String jsonData = response.body().string(); // captures the returned JSON data Log.v(TAG, jsonData);

This will capture the JSON that is returned and then display it in the log file.

Ron

Just above the log console window, there's a small search bar. Type in 'MainActivity' into that box and it will only give you the log entries tagged MainActivity, which are from your program. Jon Kussman is right, your info is 8th from the bottom.