找不到类'android.widget.ThemedSpinnerAdapter' [Android Studio]。

12

当我在一个API 21之前的设备上运行我的应用程序时,我遇到了一个奇怪的错误:

I/Choreographer: Skipped 39 frames!  The application may be doing too much work on its main thread.
12-10 07:58:44.179 4469-4472/projects.test.com.webviewtest D/dalvikvm: GC_CONCURRENT freed 156K, 4% free 4561K/4744K, paused 4ms+12ms, total 76ms
12-10 07:58:44.409 4469-4469/projects.test.com.webviewtest I/dalvikvm: Could not find method android.widget.Spinner.getPopupContext, referenced from method android.support.v7.widget.AppCompatSpinner.getPopupContext
12-10 07:58:44.409 4469-4469/projects.test.com.webviewtest W/dalvikvm: VFY: unable to resolve virtual method 18719: Landroid/widget/Spinner;.getPopupContext ()Landroid/content/Context;
12-10 07:58:44.409 4469-4469/projects.test.com.webviewtest D/dalvikvm: VFY: replacing opcode 0x6f at 0x000b
12-10 07:58:44.419 4469-4469/projects.test.com.webviewtest I/dalvikvm: Could not find method android.content.Context.getDrawable, referenced from method android.support.v7.widget.AppCompatSpinner.setPopupBackgroundResource
12-10 07:58:44.419 4469-4469/projects.test.com.webviewtest W/dalvikvm: VFY: unable to resolve virtual method 255: Landroid/content/Context;.getDrawable (I)Landroid/graphics/drawable/Drawable;
12-10 07:58:44.419 4469-4469/projects.test.com.webviewtest D/dalvikvm: VFY: replacing opcode 0x6e at 0x0004
12-10 07:58:44.429 4469-4469/projects.test.com.webviewtest I/dalvikvm: Could not find method android.widget.PopupWindow.showAsDropDown, referenced from method android.support.v7.widget.AppCompatPopupWindow.showAsDropDown
12-10 07:58:44.429 4469-4469/projects.test.com.webviewtest W/dalvikvm: VFY: unable to resolve virtual method 18641: Landroid/widget/PopupWindow;.showAsDropDown (Landroid/view/View;III)V
12-10 07:58:44.429 4469-4469/projects.test.com.webviewtest D/dalvikvm: VFY: replacing opcode 0x6f at 0x000d
12-10 07:58:44.459 4469-4469/projects.test.com.webviewtest I/dalvikvm: Could not find method android.widget.CompoundButton.drawableHotspotChanged, referenced from method android.support.v7.widget.SwitchCompat.drawableHotspotChanged
12-10 07:58:44.459 4469-4469/projects.test.com.webviewtest W/dalvikvm: VFY: unable to resolve virtual method 18333: Landroid/widget/CompoundButton;.drawableHotspotChanged (FF)V
12-10 07:58:44.459 4469-4469/projects.test.com.webviewtest D/dalvikvm: VFY: replacing opcode 0x6f at 0x0006
12-10 07:58:44.559 4469-4469/projects.test.com.webviewtest E/dalvikvm: Could not find class 'android.widget.ThemedSpinnerAdapter', referenced from method android.support.v7.widget.AppCompatSpinner$DropDownAdapter.<init>
12-10 07:58:44.569 4469-4469/projects.test.com.webviewtest W/dalvikvm: VFY: unable to resolve instanceof 2184 (Landroid/widget/ThemedSpinnerAdapter;) in Landroid/support/v7/widget/AppCompatSpinner$DropDownAdapter;
12-10 07:58:44.569 4469-4469/projects.test.com.webviewtest D/dalvikvm: VFY: replacing opcode 0x20 at 0x0016

实际上,我没有收到ANR或者“很遗憾,您的应用停止运行”这样的提示,这个应用程序会默默退出到主活动界面。

我的应用程序中没有使用任何重量级图片,只有一个带有四个下拉菜单的页面。

特别地,这一行文字被标为红色:

E/dalvikvm: Could not find class 'android.widget.ThemedSpinnerAdapter', referenced from method android.support.v7.widget.AppCompatSpinner$DropDownAdapter.<init>

但是由于我没有使用Eclipse,因此我确信我已经通过Gradle正确导入了所需的内容:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "projects.test.com.webviewtest"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
}

请检查您在布局中的旋转视图是否与使用findViewById检索到的视图匹配,也就是说,请检查类型转换,因此,如果您有AppCompatSpinner或自定义类,请确保将findViewById强制转换为相同的类。 - Mouloud
如果您在使用Parse时遇到此错误消息,请查看以下问题: https://dev59.com/iFwX5IYBdhLWcg3wwhyq#34968810 - Ojonugwa Jude Ochalifu
4个回答

5
在我的情况下,解决方法是在布局XML文件中删除使用android:tint="?attr/colorControlNormal"。也许这对其他人有帮助。

1

我解决了这个问题,看了一下我的项目中的compileSdkVersion。我有4个模块,其中3个使用sdk 22编译,一个使用sdk 23编译。

当我将它们全部改为sdk 22时,问题得到解决。因此,我的建议是检查SDK版本,并为项目中的所有模块选择相同的数字。

干杯


我觉得问题可能出在SDK版本23上。 - BlackPearl

1
我也遇到了与Spinner相同的问题,它在某些设备上运行而在某些设备上不运行。因为我放置了setAdapter(null)。因此它表现出这种行为。取而代之的是,放置ArrayList arrayList = new ArrayList(); spinner.setAdapter(new ArrayAdapter<String>(activity.this, android.R.layout.simple_dropdown_item_1line, arrayList));,然后它将在所有设备中工作。

0
在你的layout.xml中包含以下内容...
     # xmlns:app="http://schemas.android.com/apk/res-auto"

请确保在设置监听器事件之后,将您的ArrayList设置到Spinner中,
祝编码愉快.....

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接