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 Stack Overflow by Agoeng Liu
, 1 year ago
Unable to start activity ComponentInfo{com.avian.apps.avian/com.avian.apps.avian.LoginActivity}: android.os.NetworkOnMainThreadException
via Appcelerator JIRA by Stefan Axelsson, 1 year ago
Unable to start activity ComponentInfo{com.derp.herp/com.derp.herp.HerpderpActivity}: android.os.NetworkOnMainThreadException
via Stack Overflow by Mohit
, 2 years ago
Unable to start activity ComponentInfo{com.androidhive.jsonparsing/com.androidhive.jsonparsing.AndroidJSONParsingActivity}: android.os.NetworkOnMainThreadException
via Stack Overflow by michalsol
, 2 years ago
Unable to start activity ComponentInfo{com.example.testy/com.example.testy.MainActivity}: android.os.NetworkOnMainThreadException
via Stack Overflow by Droid Beginner
, 2 years ago
Unable to start activity ComponentInfo{in.wptrafficanalyzer.actionbarsherlocknavtab/in.wptrafficanalyzer.actionbarsherlocknavtab.MainActivity}: android.os.NetworkOnMainThreadException
via Stack Overflow by Mac
, 2 years ago
Unable to start activity ComponentInfo{com.example.json.mapview/com.example.json.mapview.Main}: android.os.NetworkOnMainThreadException
android.os.NetworkOnMainThreadException: 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)	at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)	at libcore.io.IoBridge.connectErrno(IoBridge.java:131)	at libcore.io.IoBridge.connect(IoBridge.java:116)	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)	at java.net.Socket.connect(Socket.java:847)	at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:288)	at net.sourceforge.jtds.jdbc.SharedSocket.(SharedSocket.java:251)	at net.sourceforge.jtds.jdbc.JtdsConnection.(JtdsConnection.java:331)	at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184)	at java.sql.DriverManager.getConnection(DriverManager.java:175)	at java.sql.DriverManager.getConnection(DriverManager.java:209)	at com.avian.apps.avian.ConnectionClass.getConnection(ConnectionClass.java:25)	at com.avian.apps.avian.LoginActivity.onCreate(LoginActivity.java:36)	at android.app.Activity.performCreate(Activity.java:5117)	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)	at android.app.ActivityThread.access$600(ActivityThread.java:145)	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)	at android.os.Handler.dispatchMessage(Handler.java:99)	at android.os.Looper.loop(Looper.java:137)	at android.app.ActivityThread.main(ActivityThread.java:5099)	at java.lang.reflect.Method.invokeNative(Native Method)	at java.lang.reflect.Method.invoke(Method.java:511)	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:803)	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:570)	at dalvik.system.NativeStart.main(Native Method)