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
, 2 years ago
Could not execute method for android:onClick
via GitHub by hassaanjamil
, 7 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
, 2 years ago
Could not execute method for android:onClick
via Stack Overflow by Zahraa Fatma
, 2 years ago
Could not execute method for android:onClick
android.os.NetworkOnMainThreadException: 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)	at java.net.InetAddress.lookupHostByName(InetAddress.java:431)	at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)	at java.net.InetAddress.getAllByName(InetAddress.java:215)	at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)	at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188)	at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157)	at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100)	at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357)	at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340)	at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)	at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:433)	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:114)	at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:563)	at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:540)	at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:227)	at org.jsoup.helper.HttpConnection.get(HttpConnection.java:216)	at com.example.application.grappingawebsite.MainActivity.get(MainActivity.java:29)	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:5198)	at android.view.View$PerformClick.run(View.java:21147)	at android.os.Handler.handleCallback(Handler.java:739)	at android.os.Handler.dispatchMessage(Handler.java:95)	at android.os.Looper.loop(Looper.java:148)	at android.app.ActivityThread.main(ActivityThread.java:5417)	at java.lang.reflect.Method.invoke(Native Method)	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)