找不到方法 onClick_Foo(View) - 第一次在 Android Lollipop 上运行 [英] Could not find a method onClick_Foo(View) - first time running on Android Lollipop

查看:27
本文介绍了找不到方法 onClick_Foo(View) - 第一次在 Android Lollipop 上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大约一年前的应用,在 Play 商店中处于测试阶段,经过了数十次修改.突然间我收到一个错误:

I have an app that is about a year old, is on the Play store in beta, has gone through dozens of revisions. All of a sudden I'm getting an error:

在活动类中找不到方法 onClick_Foo(View)android.view.ContextThemeWrapper 用于视图类上的 onClick 处理程序id 为 'Foo_Button' 的 android.widget.Button

Could not find a method onClick_Foo(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'Foo_Button'

我的 XML 中定义的 7 个按钮中的每一个都出现此错误.从昨天开始,我已经将 appcompat-v7 从 21.0.3 更新到 22.0.0,还首次将我的测试设备从 KitKat 升级到了 Lollipop.

I'm getting this error on every one of the 7 buttons defined in my XML. Since yesterday I've updating appcompat-v7 from 21.0.3 to 22.0.0 but also upgraded my testing device from KitKat to Lollipop for the first time.

我仔细检查了拼写、大小写,没有一个常见的嫌疑人能解释这一点.这是相关代码的示例.让我知道您是否觉得有更多帮助.(该活动有 915 行代码和 186 个 xml,所以不要要求全部内容).在运行 Lollipop 5.0.1 的 Verizon Note 4 上进行测试

I've double-checked spellings, capitalizations, none of the usual suspects explains this. Here's a sample of the relevant code. Let me know if you feel more would be helpful. (The activity has 915 lines of code and the xml 186, so don't ask for the whole thing). Testing on a Verizon Note 4 running Lollipop 5.0.1

activity_pick.xml:

activity_pick.xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:theme="@style/AppTheme"
    tools:context="com.myapp.Pick"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Ratings_Button"
            android:textSize="16dp"
            android:text="@string/Pick_Ratings_Button"
            android:onClick="onClick_Ratings"
            android:background="@android:drawable/btn_default"/>
</LinearLayout>
</ScrollView>

Pick.java:

public class Pick_Restaurant extends ActionBarActivity {
    public void onClick_Ratings (View v) {
        Intent intent = new Intent(mContext, Ratings.class);
        startActivityForResult(intent,RATINGS);
    }
}

build.gradle:

build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 59
    versionName "0.6.4"
}

...

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:7.0.0'
    compile files('libs/mobileservices-1.1.5.jar')
}

日志完全错误:

04-08 17:06:40.578    3508-3508/com.myapp.debug E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.myapp.debug, PID: 3508
    java.lang.IllegalStateException: Could not find a method onClick_Ratings(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'Ratings_Button'
            at android.view.View$1.onClick(View.java:4234)
            at android.view.View.performClick(View.java:5191)
            at android.view.View$PerformClick.run(View.java:20916)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5974)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
     Caused by: java.lang.NoSuchMethodException: onClick_Ratings [class android.view.View]
            at java.lang.Class.getMethod(Class.java:665)
            at android.view.View$1.onClick(View.java:4227)
            at android.view.View.performClick(View.java:5191)
            at android.view.View$PerformClick.run(View.java:20916)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5974)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

推荐答案

看来这是 Android 5.0 的新问题.

It looks like this is a new issue with Android 5.0.

this anwer,从布局 xml 中删除 Theme 为他们解决了这个问题.

From this anwer, removing the Theme from the layout xml fixed this issue for them.

所以在你的情况下,从你的布局中删除 theme :

So in your case, remove the theme from your layout:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <!--android:theme="@style/AppTheme"--> <!-- Remove this -->
    <!--................-->
  </ScrollView>

并改为在 AndroidManifest.xml 中添加主题:

And add the theme in the AndroidManifest.xml instead:

android:theme="@android:style/AppTheme"

这篇关于找不到方法 onClick_Foo(View) - 第一次在 Android Lollipop 上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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