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

i can't see the json data in the logcat???

i have done everything the teacher has said but i just cant get my data in the logcat i don't know what the problem is. first i added network state in my manifest then i uninstalled the app from the emulator like some others did but still i am not able to get any information in logcat.

my code is:- ``` public static final String TAG = MainActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    String forecastUrl = "http://dataservice.accuweather.com/locations/v1/cities/geoposition/search?apikey=nnwxRbmWqGpkXxqTJqitKy8PzcQ8gAsc&q=26.140421%2C85.358368&details=true";

    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(@NotNull Call call, @NotNull IOException e) {

        }

        @Override

        public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
            try {
                if(response.isSuccessful()){
                    Log.v(TAG,response.body().string());
                    Log.d(TAG,"THIS IS WORKING");
                }
            } catch(IOException e){
                Log.e(TAG,"io Exception caught:",e);
            }

        }
    });
    Log.d(TAG,"hooray ui is running");


}

}```

and my manifest code is this:- ```<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pratyush.weatherella"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>```

i have tried everything that has been said in community still no results

my logcat :- 2020-05-05 19:50:56.127 25100-25100/? E/ush.weatherell: Unknown bits set in runtime_flags: 0x8000 2020-05-05 19:50:57.357 25100-25152/com.pratyush.weatherella D/libEGL: Emulator has host GPU support, qemu.gles is set to 1. 2020-05-05 19:50:57.357 25100-25152/com.pratyush.weatherella W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied) 2020-05-05 19:50:57.350 25100-25100/com.pratyush.weatherella W/RenderThread: type=1400 audit(0.0:180): avc: denied { write } for name="property_service" dev="tmpfs" ino=9468 scontext=u:r:untrusted_app:s0:c140,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 2020-05-05 19:50:57.423 25100-25152/com.pratyush.weatherella D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so 2020-05-05 19:50:57.430 25100-25152/com.pratyush.weatherella D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so 2020-05-05 19:50:57.436 25100-25152/com.pratyush.weatherella D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so 2020-05-05 19:50:57.785 25100-25100/com.pratyush.weatherella W/ush.weatherell: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 2020-05-05 19:50:57.787 25100-25100/com.pratyush.weatherella W/ush.weatherell: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 2020-05-05 19:50:58.605 25100-25100/com.pratyush.weatherella D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2020-05-05 19:50:58.691 25100-25100/com.pratyush.weatherella D/MainActivity: hooray ui is running 2020-05-05 19:50:58.894 25100-25150/com.pratyush.weatherella D/HostConnection: HostConnection::get() New Host Connection established 0xde43fe10, tid 25150 2020-05-05 19:50:58.902 25100-25150/com.pratyush.weatherella D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 2020-05-05 19:50:58.913 25100-25150/com.pratyush.weatherella W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2020-05-05 19:50:59.077 25100-25150/com.pratyush.weatherella D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0 2020-05-05 19:50:59.077 25100-25150/com.pratyush.weatherella D/EGL_emulation: eglCreateContext: 0xebb8ca60: maj 2 min 0 rcv 2 2020-05-05 19:50:59.085 25100-25150/com.pratyush.weatherella D/EGL_emulation: eglMakeCurrent: 0xebb8ca60: ver 2 0 (tinfo 0xf4c894a0) 2020-05-05 19:50:59.155 25100-25150/com.pratyush.weatherella W/Gralloc3: mapper 3.x is not supported 2020-05-05 19:50:59.159 25100-25150/com.pratyush.weatherella D/HostConnection: createUnique: call 2020-05-05 19:50:59.160 25100-25150/com.pratyush.weatherella D/HostConnection: HostConnection::get() New Host Connection established 0xde441670, tid 25150 2020-05-05 19:50:59.164 25100-25150/com.pratyush.weatherella D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_2 2020-05-05 19:50:59.166 25100-25150/com.pratyush.weatherella D/eglCodecCommon: allocate: Ask for block of size 0x1000 2020-05-05 19:50:59.166 25100-25150/com.pratyush.weatherella D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ffff4000 size 0x2000 2020-05-05 19:50:59.442 25100-25150/com.pratyush.weatherella D/EGL_emulation: eglMakeCurrent: 0xebb8ca60: ver 2 0 (tinfo 0xf4c894a0) 2020-05-05 19:50:59.475 25100-25150/com.pratyush.weatherella D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0 2020-05-05 19:50:59.526 25100-25123/com.pratyush.weatherella I/ush.weatherell: NativeAlloc concurrent copying GC freed 4032(389KB) AllocSpace objects, 0(0B) LOS objects, 50% free, 1507KB/3043KB, paused 1.224ms total 349.508ms 2020-05-05 19:50:59.952 25100-25150/com.pratyush.weatherella I/OpenGLRenderer: Davey! duration=899ms; Flags=1, IntendedVsync=293364822722826, Vsync=293364822722826, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=293364827600320, AnimationStart=293364827698120, PerformTraversalsStart=293364827753720, DrawStart=293365209392520, SyncQueued=293365216980420, SyncStart=293365485018220, IssueDrawCommandsStart=293365485099420, SwapBuffers=293365784434220, FrameCompleted=293365990661620, DequeueBufferDuration=176000, QueueBufferDuration=2749000,

can someone help me fast because i just can't move forward from this i have been trying for 5 hours now

Log.d line i have only added to check it was working or not ,before that also it was not working.

1 Answer

Meghan Gill
Meghan Gill
4,220 Points

I'm not sure what version of Android you were using but there has been a behavior change to all apps that target Android 9 Pie and above. By default Http requests don't work. Because the request is not made to Log v does not appear in the Logcat. In order to make http network requests you have to specify it in the Android Manifest file. In the application tag add android: usesCleartextTraffic="true". See stack overflow:

https://stackoverflow.com/questions/51902629/how-to-allow-all-network-connection-types-http-and-https-in-android-9-pie