Could not find a method XXX(View) in the activity class
2014-12-01 16:42
411 查看
偶然调试由于疏忽出现的一个问题,在此记录下以防后面再犯。
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的监听函数最为稳妥。
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的监听函数最为稳妥。
相关文章推荐
- java.lang.IllegalStateException: Could not find a method capture(View) in the activity class
- 使用布局的Onclick属性运行出现“Could not find a method~~(View) in the activity class com.~~”
- java.lang.IllegalStateException: Could not find a method false(View) in the activity class com.xuan
- Could not find class XXX referenced from method XXX.<YYY>
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.j
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class
- AChartEnginee Could not find class 'org.achartengine.chart.PointStyle[]', referenced from method xxx
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.j
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.j
- Could not find a price list in Ordered UOM xxx and Primary UOM of the item
- JMeter命令行执行及问题解决 Error in NonGUIDriver java.lang.RuntimeException: Could not find the TestPlan class!
- 随记(三)--Xcode故事板拖拉时,could not insert new outlet connection :Could not find any information for the class named "xxx".
- Could not find a price list in Ordered UOM xxx and Primary UOM of the item
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.jdt.internal.ui.packageview.P
- Could not find class XXX referenced from method XXX.<YYY>
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart. 解决方法
- Eclipse:Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.
- Could not create the view: Plug-in org.eclipse.jdt.ui was unable to load class org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart