Play Store Crash Report: IllegalStateException on android.view.View$DeclaredOnClickListener.onClick

Viewed 1148

One of my apps picked up some crash reports for IllegalStateException. The Stack Traces say it's coming from android.view.View$DeclaredOnClickListener.onClick(view). I have never come across this error in my testing or daily use (I use the app myself on a daily basis on a Samsung Note 4 running Android 6.0.1). Honestly I don't know where to begin to look because the Stack Trace doesn't seem to even refer to any of my own code, just platform code. What am I missing? This version does use the support library, but not fragments, which is where other solutions to this error have been referring to.

Below I've pasted one of the Stack Traces. This is from a Moto G Turbo running Android 6.0

java.lang.IllegalStateException: 
  at android.view.View$DeclaredOnClickListener.onClick(View.java:4455)
  at android.view.View.performClick(View.java:5201)
  at android.view.View$PerformClick.run(View.java:21163)
  at android.os.Handler.handleCallback(Handler.java:746)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5443)
  at java.lang.reflect.Method.invoke(Native Method:0)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.lang.reflect.InvocationTargetException: 
  at java.lang.reflect.Method.invoke(Native Method:0)
  at android.view.View$DeclaredOnClickListener.onClick(View.java:4450)
3 Answers

I recently received the same kind of error reports for one of my two programs, and these crashes occurred on Android 6.0.1 and 7.1. The affected app had been in the store for many months, but this phenomenon was totally new to me and repeated within a few days with is quite improbable from a statistic point of view.

However, FrearTheCron's explanations have been extremely helpful, but are finally not satisfying. First, the "illegal state exception" should have appeared in line 4455, but line 4455 handles an "IllegalAccessException", while the first one is handled in line 4458. This is a contradiction which I do not have any explanation for. Maybe it's a bug in the Java VM.

Further, I checked all "android:onClick" entries and callbacks in my app, and all of these have rather unique names and thus do not have variants with same names and different parameters.

These examinations make me think that the problem is not caused by a coding bug in the app, but by an Android misbehaviour.

But how could this happen, and how could this be avoided? One of my apps uses two activities, while the other one uses only one, but with fragments. Only the app with two activities is affected. My theory is that Android gets confused with the views and activities, possibly triggered by some strange pause/stop/destroy/create/start/resume activity state change pattern, and tries to associate the view to the wrong activity. For example the view of my UM Player shows the tracks of an album, the system detects a click on a track, but this click is sent to the other activity, which shows the albums on the device and cannot handle the click-to-track callback. The result would be as described in the crash report.

Thus I am going to change my app in that way that both activities have callbacks for each "android::onClick" and will ignore calls sent to the wrong handler.

Maybe this helps. Any further light in the darkness would be highly appreciated.

I had an identical error from the play store. There is certainly not enough info to quickly point to a problem. FearTheCron's answer led me to look at my xml for android:onClick statements. I have 6 statements and didn't see any problems at first, then I noticed I had inadvertently created a setOnClickListener as well for one of them. I didn't see any problems in my tests on four different phones and tablets over a month of use. I removed the setOnClickListener. I'm not sure this will fix the problem, but I should have been more careful.

Related