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 trialMario Zamora
1,396 PointsWhy can't i get the result from the service in the video ?
hi,
Anybody could help me to identify the error i got, because in the video Ben shows in the logcat tab the data extrated from the service however i don't get such result. Following i add what in my Logcat tab displays:
06-02 07:14:33.864 1530-2023/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mario.stormy/.MainActivity} from uid 0 on display 0 06-02 07:14:33.899 1530-1872/system_process I/ActivityManager: Start proc 2696:com.example.mario.stormy/u0a59 for activity com.example.mario.stormy/.MainActivity 06-02 07:14:40.726 2696-2696/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.mario.stormy, PID: 2696 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mario.stormy/com.example.mario.stormy.MainActivity}: android.os.NetworkOnMainThreadException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273) at java.net.InetAddress.lookupHostByName(InetAddress.java:431) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) at java.net.InetAddress.getAllByName(InetAddress.java:215) at okhttp3.Dns$1.lookup(Dns.java:39) at okhttp3.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:173) at okhttp3.internal.http.RouteSelector.nextProxy(RouteSelector.java:139) at okhttp3.internal.http.RouteSelector.next(RouteSelector.java:81) at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:172) at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123) at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93) at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296) at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248) at okhttp3.RealCall.getResponse(RealCall.java:243) at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163) at okhttp3.RealCall.execute(RealCall.java:57) at com.example.mario.stormy.MainActivity.onCreate(MainActivity.java:35) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 06-02 07:14:40.727 1530-1872/system_process W/ActivityManager: Force finishing activity com.example.mario.stormy/.MainActivity 06-02 07:14:41.031 1530-1872/system_process I/WindowManager: Screenshot max retries 4 of Token{d87a37e ActivityRecord{1dd139 u0 com.example.mario.stormy/.MainActivity t99 f}} appWin=Window{f6b6e71 u0 Starting com.example.mario.stormy} drawState=4 06-02 07:14:41.533 1530-1545/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{1dd139 u0 com.example.mario.stormy/.MainActivity t99 f} 06-02 07:32:35.923 1530-1900/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mario.stormy/.MainActivity} from uid 0 on display 0 06-02 07:32:36.253 1530-1808/system_process I/ActivityManager: Start proc 2958:com.example.mario.stormy/u0a59 for activity com.example.mario.stormy/.MainActivity 06-02 07:32:37.353 2987-2995/? W/dex2oat: Compilation of java.lang.Object com.example.mario.stormy.MainActivity.access$super(com.example.mario.stormy.MainActivity, java.lang.String, java.lang.Object[]) took 384.893ms 06-02 07:32:38.677 1530-1542/system_process W/ActivityManager: Force finishing activity com.example.mario.stormy/.MainActivity 06-02 07:32:38.980 1530-1542/system_process I/WindowManager: Screenshot max retries 4 of Token{7494367 ActivityRecord{4adcb26 u0 com.example.mario.stormy/.MainActivity t100 f}} appWin=Window{831385f u0 Starting com.example.mario.stormy} drawState=4 06-02 07:37:23.114 1530-1808/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mario.stormy/.MainActivity} from uid 0 on display 0 06-02 07:37:23.190 1530-1541/system_process I/ActivityManager: Start proc 3129:com.example.mario.stormy/u0a59 for activity com.example.mario.stormy/.MainActivity 06-02 07:37:27.047 1530-1550/system_process I/ActivityManager: Displayed com.example.mario.stormy/.MainActivity: +3s879ms 06-02 07:40:39.721 1530-1550/system_process I/WindowManager: Screen frozen for +478ms due to Window{24309a2 u0 com.example.mario.stormy/com.example.mario.stormy.MainActivity} 06-02 07:40:48.428 1530-1567/system_process W/InputDispatcher: channel '24309a2 com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 06-02 07:40:48.429 1530-1567/system_process E/InputDispatcher: channel '24309a2 com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 06-02 07:40:48.430 1530-1541/system_process I/WindowState: WIN DEATH: Window{24309a2 u0 com.example.mario.stormy/com.example.mario.stormy.MainActivity} 06-02 07:40:48.430 1530-1541/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '24309a2 com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' 06-02 07:40:57.180 1530-1872/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mario.stormy/.MainActivity} from uid 0 on display 0 06-02 07:40:57.259 1530-2019/system_process I/ActivityManager: Start proc 6346:com.example.mario.stormy/u0a59 for activity com.example.mario.stormy/.MainActivity 06-02 07:41:00.680 1530-1550/system_process I/ActivityManager: Displayed com.example.mario.stormy/.MainActivity: +3s448ms 06-02 07:42:24.966 1530-1567/system_process W/InputDispatcher: channel '9ad6fec com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 06-02 07:42:24.966 1530-1567/system_process E/InputDispatcher: channel '9ad6fec com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 06-02 07:42:24.970 1530-2023/system_process I/WindowState: WIN DEATH: Window{9ad6fec u0 com.example.mario.stormy/com.example.mario.stormy.MainActivity} 06-02 07:42:24.970 1530-2023/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '9ad6fec com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' 06-02 07:42:24.997 1530-1808/system_process W/ActivityManager: Force removing ActivityRecord{edfbf64 u0 com.example.mario.stormy/.MainActivity t103}: app died, no saved state 06-02 07:42:30.378 1530-5999/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mario.stormy/.MainActivity} from uid 0 on display 0 06-02 07:42:30.409 1530-2023/system_process I/ActivityManager: Start proc 7720:com.example.mario.stormy/u0a59 for activity com.example.mario.stormy/.MainActivity 06-02 07:42:32.938 1530-1550/system_process I/ActivityManager: Displayed com.example.mario.stormy/.MainActivity: +2s541ms 06-02 07:44:16.092 1530-1567/system_process W/InputDispatcher: channel '20f703f com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 06-02 07:44:16.092 1530-1567/system_process E/InputDispatcher: channel '20f703f com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 06-02 07:44:16.093 1530-1872/system_process I/WindowState: WIN DEATH: Window{20f703f u0 com.example.mario.stormy/com.example.mario.stormy.MainActivity} 06-02 07:44:16.093 1530-1872/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '20f703f com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' 06-02 07:44:16.132 1530-1873/system_process W/ActivityManager: Force removing ActivityRecord{6632429 u0 com.example.mario.stormy/.MainActivity t104}: app died, no saved state 06-02 07:44:23.137 1530-1873/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mario.stormy/.MainActivity} from uid 0 on display 0 06-02 07:44:23.179 1530-1872/system_process I/ActivityManager: Start proc 9313:com.example.mario.stormy/u0a59 for activity com.example.mario.stormy/.MainActivity 06-02 07:44:24.081 9337-9337/? W/dex2oat: Compilation of java.lang.Object com.example.mario.stormy.MainActivity.access$super(com.example.mario.stormy.MainActivity, java.lang.String, java.lang.Object[]) took 406.378ms 06-02 07:44:25.559 9313-9313/com.example.mario.stormy D/MainActivity: Main UI code is running! 06-02 07:44:25.932 1530-1550/system_process I/ActivityManager: Displayed com.example.mario.stormy/.MainActivity: +2s766ms 06-02 07:44:52.532 1530-1567/system_process W/InputDispatcher: channel '309fa1f com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 06-02 07:44:52.532 1530-1567/system_process E/InputDispatcher: channel '309fa1f com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 06-02 07:44:52.538 1530-2019/system_process I/WindowState: WIN DEATH: Window{309fa1f u0 com.example.mario.stormy/com.example.mario.stormy.MainActivity} 06-02 07:44:52.538 1530-2019/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel '309fa1f com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' 06-02 07:45:01.627 1530-5997/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mario.stormy/.MainActivity} from uid 0 on display 0 06-02 07:45:01.820 1530-1541/system_process I/ActivityManager: Start proc 9816:com.example.mario.stormy/u0a59 for activity com.example.mario.stormy/.MainActivity 06-02 07:45:03.665 9816-9816/com.example.mario.stormy D/MainActivity: Main UI code is running! 06-02 07:45:04.265 1530-1550/system_process I/ActivityManager: Displayed com.example.mario.stormy/.MainActivity: +2s467ms 06-02 08:06:53.142 1530-1567/system_process W/InputDispatcher: channel 'cea16eb com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 06-02 08:06:53.142 1530-1567/system_process E/InputDispatcher: channel 'cea16eb com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 06-02 08:06:53.143 1530-1900/system_process I/WindowState: WIN DEATH: Window{cea16eb u0 com.example.mario.stormy/com.example.mario.stormy.MainActivity} 06-02 08:06:53.143 1530-1900/system_process W/InputDispatcher: Attempted to unregister already unregistered input channel 'cea16eb com.example.mario.stormy/com.example.mario.stormy.MainActivity (server)' 06-02 08:06:53.201 1530-2019/system_process W/ActivityManager: Force removing ActivityRecord{a5ebcf5 u0 com.example.mario.stormy/.MainActivity t106}: app died, no saved state 06-02 08:06:56.197 1530-1900/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.mario.stormy/.MainActivity} from uid 0 on display 0 06-02 08:06:56.270 1530-1542/system_process I/ActivityManager: Start proc 28659:com.example.mario.stormy/u0a59 for activity com.example.mario.stormy/.MainActivity 06-02 08:06:57.975 28659-28659/com.example.mario.stormy D/MainActivity: Main UI code is running! 06-02 08:06:58.283 1530-1550/system_process I/ActivityManager: Displayed com.example.mario.stormy/.MainActivity: +2s38ms
As you can see isn't the same as ben got.
:(
Thank you in advance for your asistance.
1 Answer
Seth Kroger
56,413 PointsIt looks like StrictMode is enabled on your app. This is used to catch common mistakes that can cause your app to freeze or become unresponsive. What you are doing, making a network call on the main thread is such a mistake. Ben goes over this in subsequent videos, and shows you how OkHttp should be used to avoid it. Where StrictMode is enabled, you can change penaltyDeath()
to penaltyLog()
to have it just log the violation instead of crashing.