如果使用主题,则在活动类TintContextWrapper中无法为onClick找到方法onClick(View) [英] Could not find a method onClick(View) in the activity class TintContextWrapper for onClick if using themes
问题描述
在添加为我的应用选择深色或浅色主题的功能之后,我最近收到了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
异常.
I'm getting the 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
exception recently after adding the ability to select a dark or light theme for my app.
我确实在清单中设置了主题,然后使用以下BaseActivity
:
I do set the theme in the manifest and then I use following 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的设备上收到了问题...
Any ideas what else could cause this issue? I got the issue from a device running 4.2.2...
无法使用的解决方案
- 类似的问题建议从xml文件中删除
theme
标记=>我不在xml中使用它,所以对我而言不是这种情况
- similar issues suggest to remove the
theme
tag from the xml file => I'm not using it in my xml, so this is not the case for me
Stacktrace
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
.
对你有用.
其他方式.
您可以在活动中将setOnClickListener
用于Click事件.
You can use setOnClickListener
in Your Activity for Click event.
这篇关于如果使用主题,则在活动类TintContextWrapper中无法为onClick找到方法onClick(View)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!