Could not find a method XXX(View) in the activity class
来源:互联网 发布:mac 打开finder快捷键 编辑:程序博客网 时间:2024/05/17 08:41
偶然调试由于疏忽出现的一个问题,在此记录下以防后面再犯。
log
E/AndroidRuntime(13796): java.lang.IllegalStateException: Could not find a method XXX(View) in the activity class com.fbp.mytest.XXXActivity for onClick handler on view class android.widget.Button with id 'search'
出现这个错误的原因在于,我在代码中用到了Fragment,因此减少了部分Activity的数量,都是直接写成了Fragment但是在布局中因为想省事直接将Button的响应用了android:onClick属性来调用Fragment中的方法,但是结果就出现了上面的错误。原因是onClick貌似只会到MainActivity中去寻找方法,而不会在对应Fragment的实现代码里去找这个方法,于是出现了方法找不到的错误。
所以如果说想用到这个属性,应该必须是要在MainActivity的布局中使用了。具体更详细的原因暂时不清楚,留待以后了解吧。一般来说还是在类中独立去写Button的监听函数最为稳妥。
2 0
- Could not find a method XXX(View) in the activity class
- java.lang.IllegalStateException: Could not find a method capture(View) in the activity class
- java.lang.IllegalStateException: Could not find a method false(View) in the activity class com.xuan
- java.lang.IllegalStateException: Could not find a method add(View) in the activity class haha.com.e
- 使用布局的Onclick属性运行出现“Could not find a method~~(View) in the activity class com.~~”
- java.lang.IllegalStateException: Could not find method onClickcrea(View) in a parent or ancestor Con
- Could not find a price list in Ordered UOM xxx and Primary UOM of the item
- Could not find class xxx referenced from method xxx.access$super
- Could not find method update(View) in a parent or ancestor Context for android:onClick attribute def
- could not find a getter for in class方法解决
- could not find a getter for ... in class ...
- Could not find a getter for salesName in class
- could not find a getter for ... in class ...
- could not find a getter for ... in class ...
- Hibernate: Could not find a getter for **** in class
- Could not find a getter for.. in class.. 异常原因
- Could not find class '****', referenced from method #####
- Could not find class '****', referenced from method #####
- LR:接口性能测试中的应用服务器监控数据指标分析(Linx内存管理 和 性能学习)
- 一.关于Vmware的网络连接
- 常见Java面试题 – 第四部分:迭代(iteration)和递归(recursion)
- Sqoop的安装与测试
- 部署与管理ZooKeeper(转)
- Could not find a method XXX(View) in the activity class
- 网络基本功系列:细说路由(下)
- 送礼的几大原则
- 2014.11.28笔记
- 学习IOS遇到的错—引入libxml包出错
- 指针与引用
- C#设计模式(1)——单例模式
- CListCtrl控件使用方法总结 --很详细(一)
- Java实现二分查找