我在活动类
android.support.v7.widget.TintContextWrapper中为onClick处理程序找到了一个onClick(View)方法onView处理程序,最近在添加了select的能力之后的视图类android.support.v7.widget.AppCompatButton异常我的应用程序的黑暗或浅色主题.
我在清单中设置主题,然后使用以下BaseActivity:
public abstract class BaseActivity extends AppCompatActivity { private final int mLightTheme; private final int mDarkTheme; public BaseActivity(int lightTheme,int darkTheme) { mLightTheme = lightTheme; mDarkTheme = darkTheme; } @Override protected void onCreate(Bundle savedInstanceState) { setTheme(MainApp.getPrefs().darkTheme() ? mDarkTheme : mLightTheme); super.onCreate(savedInstanceState); } }
还有什么想法会导致这个问题吗?我从运行4.2.2的设备中得到了这个问题…
不工作的解决方案
>类似的问题建议从xml文件中删除主题标签=>我没有在我的xml中使用它,所以对我来说情况并非如此
堆栈跟踪
java.lang.IllegalStateException: Could not find a method onClick(View) in the activity class android.support.v7.widget.TintContextWrapper for onClick handler on view class android.support.v7.widget.AppCompatButton with id 'btBack' at android.view.View$1.onClick(View.java:3602) at android.view.View.performClick(View.java:4220) at android.view.View$PerformClick.run(View.java:17513) at android.os.Handler.handleCallback(Handler.java:800) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5455) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:733) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NoSuchMethodException: onClick [class android.view.View] at java.lang.Class.getConstructorOrMethod(Class.java:460) at java.lang.Class.getMethod(Class.java:915) at android.view.View$1.onClick(View.java:3595) ... 11 more java.lang.NoSuchMethodException: onClick [class android.view.View] at java.lang.Class.getConstructorOrMethod(Class.java:460) at java.lang.Class.getMethod(Class.java:915) at android.view.View$1.onClick(View.java:3595) at android.view.View.performClick(View.java:4220) at android.view.View$PerformClick.run(View.java:17513) at android.os.Handler.handleCallback(Handler.java:800) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5455) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:733) at dalvik.system.NativeStart.main(Native Method)
解决方法
将android.support.v7.widget.AppCompatButton更改为Button.
它对你有用.
另一种方式.
您可以在Your Activity for Click事件中使用setOnClickListener.