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 btusca
, 1 year ago
Could not execute method for android:onClick
via GitHub by hassaanjamil
, 4 months ago
Could not execute method for android:onClick
via GitHub by danilorosso
, 1 year ago
Could not execute method for android:onClick
via Stack Overflow by kps2501
, 1 year ago
Could not execute method for android:onClick
via Stack Overflow by Zahraa Fatma
, 1 year ago
Could not execute method for android:onClick
android.os.NetworkOnMainThreadException: 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)	at java.net.SocketOutputStream.write(SocketOutputStream.java:157)	at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)	at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)	at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)	at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)	at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)	at java.io.BufferedWriter.flush(BufferedWriter.java:254)	at com.example.rachel.testapp.MainActivity.sendMessage(MainActivity.java:88)	at java.lang.reflect.Method.invoke(Native Method)	at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)	at android.view.View.performClick(View.java:5637)	at android.view.View$PerformClick.run(View.java:22429)	at android.os.Handler.handleCallback(Handler.java:751)	at android.os.Handler.dispatchMessage(Handler.java:95)	at android.os.Looper.loop(Looper.java:154)	at android.app.ActivityThread.main(ActivityThread.java:6119)	at java.lang.reflect.Method.invoke(Native Method)	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)