java.lang.IllegalStateException: Could not find method onClickcrea(View) in a parent or ancestor Con

简介: java.lang.IllegalStateException: Could not find method onClickcrea(View) in a parent or ancestor Con
java.lang.IllegalStateException: Could not find method startChat(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.widget.Button with id 'Button'
        at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4479)
        at android.view.View$DeclaredOnClickListener.onClick(View.java:4443)
        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)

出现场景:

在一个Button中定义了onclick属性,值为startChat。

在Activity中定义一个方法。

public void startChat(View view){}

运行时,点击按钮,就会出现这个异常。


这是因为activity继承的是AppCompatActivity,默认使用的主题是@style/AppTheme

把activity的主题去掉,再运行就不会报错了。


个人建议还是使用onClickListener设置监听。

相关文章
|
7月前
|
IDE Java 编译器
Java The method compareTo(Integer) in the type解决方法
Java编程过程中,Integer对象(或其它继承自Number类的包装类对象)使用Number包装类内置的compareTo()方法来比较调用对象和参数之间的大小的时候,Java的集成开发环境IDE或编译器给出了提示:The method compareTo(Integer) in the type Integer is not applicable for the arguments (Float)
61 5
|
fastjson
修复fastjson的java.lang.IllegalArgumentException: Comparison method violates its general contract!
修复fastjson的java.lang.IllegalArgumentException: Comparison method violates its general contract!
118 0
|
7月前
|
设计模式 Java 容器
【设计模式】JAVA Design Patterns——Async Method Invocation(异步方法调用模式)
【设计模式】JAVA Design Patterns——Async Method Invocation(异步方法调用模式)
|
5月前
|
存储 Java 编译器
Java面试题:描述方法区(Method Area)的作用以及它在JVM中的演变(从永久代到元空间)
Java面试题:描述方法区(Method Area)的作用以及它在JVM中的演变(从永久代到元空间)
64 3
|
6月前
|
Java 测试技术
Java反射之Method的invoke方法详解
Java反射之Method的invoke方法详解
|
Java Docker 微服务
【Java异常】Caused by: java.lang.IllegalArgumentException: method GET must not have a request body
【Java异常】Caused by: java.lang.IllegalArgumentException: method GET must not have a request body
205 1
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must b
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must b
251 0
SpringCloud Feign报错:java.lang.IllegalStateException: Method has too many Body parameters
SpringCloud Feign报错:java.lang.IllegalStateException: Method has too many Body parameters
237 0
|
7月前
|
Java Spring
java.lang.Exception: Method a() should be public
java.lang.Exception: Method a() should be public
77 0
|
7月前
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘quanZiController‘ method
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map ‘quanZiController‘ method
54 0