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 Yousaf Iqbal
, 2 years ago
android.os.NetworkOnMainThreadException: 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)	at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)	at libcore.io.IoBridge.connectErrno(IoBridge.java:144)	at libcore.io.IoBridge.connect(IoBridge.java:112)	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)	at java.net.Socket.connect(Socket.java:842)	at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)	at com.mongodb.connection.SocketStream.open(SocketStream.java:58)	at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)	at com.mongodb.connection.UsageTrackingInternalConnection.open(UsageTrackingInternalConnection.java:46)	at com.mongodb.connection.DefaultConnectionPool$PooledConnection.open(DefaultConnectionPool.java:366)	at com.mongodb.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:94)	at com.mongodb.connection.DefaultConnectionPool.get(DefaultConnectionPool.java:80)	at com.mongodb.connection.DefaultServer.getConnection(DefaultServer.java:69)	at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.getConnection(ClusterBinding.java:86)	at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:184)	at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:177)	at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:141)	at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:72)	at com.mongodb.Mongo.execute(Mongo.java:747)	at com.mongodb.Mongo$2.execute(Mongo.java:730)	at com.mongodb.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:482)	at com.mongodb.MongoCollectionImpl.insertOne(MongoCollectionImpl.java:277)	at com.sujithsizon.lzlogin3.LoginActivity.yalla(LoginActivity.java:224)	at com.sujithsizon.lzlogin3.LoginActivity$3$1.onCompleted(LoginActivity.java:99)	at com.facebook.GraphRequest$1.onCompleted(GraphRequest.java:304)	at com.facebook.GraphRequest$5.run(GraphRequest.java:1368)	at android.os.Handler.handleCallback(Handler.java:615)	at android.os.Handler.dispatchMessage(Handler.java:92)	at android.os.Looper.loop(Looper.java:137)	at android.app.ActivityThread.main(ActivityThread.java:4745)	at java.lang.reflect.Method.invokeNative(Native Method)	at java.lang.reflect.Method.invoke(Method.java:511)