Help to understand, an error crept into the application, rarely pops up, for several users, in the panel of developers I see:

java.lang.IllegalStateException: at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4532) at android.view.View$DeclaredOnClickListener.onClick(View.java:4496) at android.view.View.performClick(View.java:5265) at android.view.View$PerformClick.run(View.java:21534) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5728) at java.lang.reflect.Method.invoke(Native Method:0) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 

But I can not even understand which line in the code this error refers to, I have never come across this before.

  • Do you have a way to handle clicks not through android: onclick in xml? - mrBatonec
  • code lay out if not difficult - Rasul
  • Yes, through android: onclick. - ildar1989

1 answer 1

This happens, for example, when inside the fragment a click handler is declared via xml. Usually due to the fact that the fragment is not yet attached or not quite ready

You need to clear the android:onclick from your layout and declare the click handler via View.OnClickListener , in this case the handler is guaranteed to work at the right moment.

  • The xml attribute android:onClick works only for android:onClick markup (more precisely for the context and its heirs), it does not work in fragments, because the fragment is not the context heir, and everything is correct, of course :) - pavlofff