Searched on Google with the first line of a JAVA stack trace?

We can recommend more relevant solutions and speed up debugging when you paste your entire stack trace with the exception message. Try a sample exception.

Recommended solutions based on your search

Samebug tips

  1. ,
    via Stack Overflow by Razgriz

    Happens when you make a network call on the main UI thread of the Android application which results in a UI freeze until the network call is complete and the response is received. Instead, execute the network calls in the background: use AsyncTask.

  2. ,

    An alternative for just getting rid of the Exception is use StrictMode.ThreadPolicy to force execute on main thread.

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    

Solutions on the web

via GitHub by tuhin10
, 2 years ago
This exception has no message.
via Stack Overflow by user782104
, 2 years ago
via Stack Overflow by TheNerdFromYesterday
, 2 years ago
This exception has no message.
via Stack Overflow by Knossos
, 1 year ago
android.os.NetworkOnMainThreadException: 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)	at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:249)	at libcore.io.IoBridge.recvfrom(IoBridge.java:553)	at java.net.PlainSocketImpl.read(PlainSocketImpl.java:485)	at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)	at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)	at okio.Okio$2.read(Okio.java:139)	at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)	at okio.RealBufferedSource.read(RealBufferedSource.java:50)	at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:381)	at okhttp3.internal.Util.skipAll(Util.java:178)	at okhttp3.internal.Util.discard(Util.java:160)	at okhttp3.internal.http.Http1xStream$FixedLengthSource.close(Http1xStream.java:397)	at okio.RealBufferedSource.close(RealBufferedSource.java:396)	at okio.ForwardingSource.close(ForwardingSource.java:43)	at okio.RealBufferedSource.close(RealBufferedSource.java:396)	at okio.RealBufferedSource$1.close(RealBufferedSource.java:384)	at com.testapp.apkinstall.MainActivity.writeResponseBodyToDisk(MainActivity.java:87)	at com.testapp.apkinstall.MainActivity.access$000(MainActivity.java:24)	at com.testapp.apkinstall.MainActivity$1$1.onResponse(MainActivity.java:42)	at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:68)	at android.os.Handler.handleCallback(Handler.java:739)	at android.os.Handler.dispatchMessage(Handler.java:95)	at android.os.Looper.loop(Looper.java:135)	at android.app.ActivityThread.main(ActivityThread.java:5254)	at java.lang.reflect.Method.invoke(Native Method)	at java.lang.reflect.Method.invoke(Method.java:372)	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)