java.lang.NoSuchMethodException: [class android.view.View]

05-24 11:38:35.884: E/AndroidRuntime(1819): FATAL EXCEPTION: main
05-24 11:38:35.884: E/AndroidRuntime(1819): Process: com.example.activitytest, PID: 1819
05-24 11:38:35.884: E/AndroidRuntime(1819): java.lang.IllegalStateException: Could not find a method (View) in the activity class com.example.activitytest.ThirdActivity for onClick handler on view class android.widget.Button
05-24 11:38:35.884: E/AndroidRuntime(1819): at android.view.View$1.onClick(View.java:3810)
05-24 11:38:35.884: E/AndroidRuntime(1819): at android.view.View.performClick(View.java:4438)
05-24 11:38:35.884: E/AndroidRuntime(1819): at android.view.View$PerformClick.run(View.java:18422)
05-24 11:38:35.884: E/AndroidRuntime(1819): at android.os.Handler.handleCallback(Handler.java:733)
05-24 11:38:35.884: E/AndroidRuntime(1819): at android.os.Handler.dispatchMessage(Handler.java:95)
05-24 11:38:35.884: E/AndroidRuntime(1819): at android.os.Looper.loop(Looper.java:136)
05-24 11:38:35.884: E/AndroidRuntime(1819): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-24 11:38:35.884: E/AndroidRuntime(1819): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 11:38:35.884: E/AndroidRuntime(1819): at java.lang.reflect.Method.invoke(Method.java:515)
05-24 11:38:35.884: E/AndroidRuntime(1819): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-24 11:38:35.884: E/AndroidRuntime(1819): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-24 11:38:35.884: E/AndroidRuntime(1819): at dalvik.system.NativeStart.main(Native Method)
05-24 11:38:35.884: E/AndroidRuntime(1819): Caused by: java.lang.NoSuchMethodException: [class android.view.View]
05-24 11:38:35.884: E/AndroidRuntime(1819): at java.lang.Class.getConstructorOrMethod(Class.java:472)
05-24 11:38:35.884: E/AndroidRuntime(1819): at java.lang.Class.getMethod(Class.java:857)
05-24 11:38:35.884: E/AndroidRuntime(1819): at android.view.View$1.onClick(View.java:3803)
05-24 11:38:35.884: E/AndroidRuntime(1819): ... 11 more

 

 

button 的布局文件中 android :onclick="" 没添加方法

 

这原因是你在当前的xxxxActivity中给某一个View控件添加它没有方法,如我的错误是 button添加一个Onclick方法,所以在点击此ImageView时报错误,有可能你并没有在当前activity中实例化此imageview,只此imageview的acitivity界面中,可在此imageview的layout布局中去看看是否给此iamgeview添加一个android:onclick="true"属性

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。