0
votes

I'm using this example -

serach by keyword - youtube api

when the app trying the execute the following line it crashes:

 SearchListResponse searchResponse = search.execute();

This is the exception:

10-23 22:32:17.186: I/Adreno-EGL(14500): : EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13 10-23 22:32:17.226: D/OpenGLRenderer(14500): Enabling debug mode 0 10-23 22:32:18.167: I/System.out(14500): search 10-23 22:32:19.169: D/dalvikvm(14500): GC_FOR_ALLOC freed 189K, 3% free 9309K/9532K, paused 21ms, total 22ms 10-23 22:32:20.840: I/System.out(14500): query !!! ghh 10-23 22:32:21.111: D/dalvikvm(14500): GC_FOR_ALLOC freed 184K, 3% free 9638K/9856K, paused 16ms, total 16ms 10-23 22:32:21.121: W/ContextImpl(14500): Implicit intents with startService are not safe: Intent { act=com.google.android.youtube.api.service.START } android.content.ContextWrapper.bindService:517 com.google.android.youtube.player.internal.r.e:-1 com.google.android.youtube.player.YouTubePlayerView.a:-1 10-23 22:32:21.161: I/System.out(14500): *************************************************** 10-23 22:32:21.241: D/dalvikvm(14500): GC_FOR_ALLOC freed 374K, 5% free 9776K/10184K, paused 19ms, total 19ms 10-23 22:32:21.271: W/System.err(14500): android.os.NetworkOnMainThreadException 10-23 22:32:21.271: W/System.err(14500): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145) 10-23 22:32:21.271: W/System.err(14500): at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 10-23 22:32:21.271: W/System.err(14500): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 10-23 22:32:21.271: W/System.err(14500): at java.net.InetAddress.getAllByName(InetAddress.java:214) 10-23 22:32:21.271: W/System.err(14500): at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28) 10-23 22:32:21.271: W/System.err(14500): at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216) 10-23 22:32:21.281: W/System.err(14500): at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122) 10-23 22:32:21.281: W/System.err(14500): at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292) 10-23 22:32:21.281: W/System.err(14500): at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) 10-23 22:32:21.281: W/System.err(14500): at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) 10-23 22:32:21.281: W/System.err(14500): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) 10-23 22:32:21.281: W/System.err(14500): at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89) 10-23 22:32:21.281: W/System.err(14500): at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161) 10-23 22:32:21.281: W/System.err(14500): at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:93) 10-23 22:32:21.281: W/System.err(14500): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965) 10-23 22:32:21.281: W/System.err(14500): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410) 10-23 22:32:21.281: W/System.err(14500): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343) 10-23 22:32:21.281: W/System.err(14500): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460) 10-23 22:32:21.281: W/System.err(14500): at com.android.wetago.service.YoutubeService.getSearchResultList(YoutubeService.java:62) 10-23 22:32:21.281: W/System.err(14500): at com.android.wetago.YoutubeResultListActivity$VideoListFragment.initVideoList(YoutubeResultListActivity.java:178) 10-23 22:32:21.281: W/System.err(14500): at com.android.wetago.YoutubeResultListActivity.onCreate(YoutubeResultListActivity.java:75) 10-23 22:32:21.281: W/System.err(14500): at android.app.Activity.performCreate(Activity.java:5231) 10-23 22:32:21.281: W/System.err(14500): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 10-23 22:32:21.281: W/System.err(14500): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 10-23 22:32:21.281: W/System.err(14500): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 10-23 22:32:21.281: W/System.err(14500): at android.app.ActivityThread.access$800(ActivityThread.java:135) 10-23 22:32:21.281: W/System.err(14500): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 10-23 22:32:21.281: W/System.err(14500): at android.os.Handler.dispatchMessage(Handler.java:102) 10-23 22:32:21.281: W/System.err(14500): at android.os.Looper.loop(Looper.java:136) 10-23 22:32:21.281: W/System.err(14500): at android.app.ActivityThread.main(ActivityThread.java:5001) 10-23 22:32:21.281: W/System.err(14500): at java.lang.reflect.Method.invokeNative(Native Method) 10-23 22:32:21.281: W/System.err(14500): at java.lang.reflect.Method.invoke(Method.java:515) 10-23 22:32:21.281: W/System.err(14500): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 10-23 22:32:21.281: W/System.err(14500): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 10-23 22:32:21.281: W/System.err(14500): at dalvik.system.NativeStart.main(Native Method) 10-23 22:32:21.281: D/AndroidRuntime(14500): Shutting down VM 10-23 22:32:21.281: W/dalvikvm(14500): threadid=1: thread exiting with uncaught exception (group=0x4158aba8) 10-23 22:32:21.281: E/AndroidRuntime(14500): FATAL EXCEPTION: main 10-23 22:32:21.281: E/AndroidRuntime(14500): Process: com.android.wetago, PID: 14500 10-23 22:32:21.281: E/AndroidRuntime(14500): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.wetago/com.android.wetago.YoutubeResultListActivity}: java.lang.NullPointerException: list == null 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.app.ActivityThread.access$800(ActivityThread.java:135) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.os.Handler.dispatchMessage(Handler.java:102) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.os.Looper.loop(Looper.java:136) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.app.ActivityThread.main(ActivityThread.java:5001) 10-23 22:32:21.281: E/AndroidRuntime(14500): at java.lang.reflect.Method.invokeNative(Native Method) 10-23 22:32:21.281: E/AndroidRuntime(14500): at java.lang.reflect.Method.invoke(Method.java:515) 10-23 22:32:21.281: E/AndroidRuntime(14500): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 10-23 22:32:21.281: E/AndroidRuntime(14500): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 10-23 22:32:21.281: E/AndroidRuntime(14500): at dalvik.system.NativeStart.main(Native Method) 10-23 22:32:21.281: E/AndroidRuntime(14500): Caused by: java.lang.NullPointerException: list == null 10-23 22:32:21.281: E/AndroidRuntime(14500): at java.util.Collections.unmodifiableList(Collections.java:2283) 10-23 22:32:21.281: E/AndroidRuntime(14500): at com.android.wetago.YoutubeResultListActivity$VideoListFragment.initVideoList(YoutubeResultListActivity.java:179) 10-23 22:32:21.281: E/AndroidRuntime(14500): at com.android.wetago.YoutubeResultListActivity.onCreate(YoutubeResultListActivity.java:75) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.app.Activity.performCreate(Activity.java:5231) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 10-23 22:32:21.281: E/AndroidRuntime(14500): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 10-23 22:32:21.281: E/AndroidRuntime(14500): ... 11 more

1

1 Answers

1
votes

It's a simple network on main thread exception. You should do your API calls inside an AsyncTask.

Checkout YouTube Direct Lite for Android for example.