user9854527
user9854527

Reputation:

Android App error while the app is running

I am not able to figure out what is causing this error while the app is running. It causes the app to stop. Is it a wrong practice to sleep the main thread to finish execution of the asynchronous thread. If so why and what is a good practice?

java.lang.IllegalStateException: Could not execute method for android:onClick
    at android.view.View$DeclaredOnClickListener.onClick(View.java:4707)
    at android.view.View.performClick(View.java:5619)
    at android.view.View$PerformClick.run(View.java:22295)
    at android.os.Handler.handleCallback(Handler.java:754)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6342)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
 Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at android.view.View$DeclaredOnClickListener.onClick(View.java:4702)
    at android.view.View.performClick(View.java:5619) 
    at android.view.View$PerformClick.run(View.java:22295) 
    at android.os.Handler.handleCallback(Handler.java:754) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:163) 
    at android.app.ActivityThread.main(ActivityThread.java:6342) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770) 
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
    at com.example.sairahul5223.e_bot.Main4Activity.onButtonClickName43(Main4Activity.java:330)
    at java.lang.reflect.Method.invoke(Native Method) 
    at android.view.View$DeclaredOnClickListener.onClick(View.java:4702) 
    at android.view.View.performClick(View.java:5619) 
    at android.view.View$PerformClick.run(View.java:22295) 
    at android.os.Handler.handleCallback(Handler.java:754) 
    at android.os.Handler.dispatchMessage(Handler.java:95) 
    at android.os.Looper.loop(Looper.java:163) 
    at android.app.ActivityThread.main(ActivityThread.java:6342) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770) 

Upvotes: 2

Views: 121

Answers (1)

user1506104
user1506104

Reputation: 7106

First thing: we don't make the main thread sleep because this will cause an Application Not Responding (ANR) error.

To get the result of an asynchronous task, we normally use a callback to determine the task's status. Take a look at this answer to give you idea: How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?

Upvotes: 1

Related Questions