如果使用主题,在 onClick 的活动类 TintContextWrapper 中找不到方法 onClick(View) [英] Could not find a method onClick(View) in the activity class TintContextWrapper for onClick if using themes

查看:23
本文介绍了如果使用主题,在 onClick 的活动类 TintContextWrapper 中找不到方法 onClick(View)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到 在视图类 android.support.v7.widget.AppCompatButton 上的 onClick 处理程序的活动类 android.support.v7.widget.TintContextWrapper 中找不到方法 onClick(View) 异常.

我确实在清单中设置了主题,然后我使用以下 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

堆栈跟踪

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.

它会为你工作.

其他方式.

您可以在 Activity 中使用 setOnClickListener 进行 Click 事件.

You can use setOnClickListener in Your Activity for Click event.

这篇关于如果使用主题,在 onClick 的活动类 TintContextWrapper 中找不到方法 onClick(View)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆