[Android]IllegalStateException: Could not find method onBind(View)
FATAL EXCEPTION: main
Process: org.diql.aidldemo, PID: 2274
java.lang.IllegalStateException: Could not find method onBind(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'btn_bind'
at android.support.v7.app.AppCompatViewInflater\(DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:325) at android.support.v7.app.AppCompatViewInflater\)DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
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)
--------- beginning of system
原因:
在layout的根布局中使用了tools:context
属性,将 ayout 与一个 Activity 进行了绑定,但是在该 Activity 中进行 inflate 该 layout 时,没有发现该方法.具体可能是:
- 该方法未声明;
- 该方法没有用
public
修饰;