Android studio的AppcompatActivity错误

Lin*_*yen 14 android android-appcompat android-studio appcompatactivity

使用Android studio构建Android应用程序时出现此错误:

24192-24192/com.mkapp.apps.demo1 W/dalvikvm? VFY: unable to find class referenced in signature (Landroid/os/PersistableBundle;)
08-20 10:53:23.605  24192-24192/com.mkapp.apps.demo1 I/dalvikvm? Could not find method android.support.v7.app.AppCompatActivity.onCreate, referenced from method com.mkapp.apps.demo1.TourActivity.onCreate
08-20 10:53:23.605  24192-24192/com.mkapp.apps.demo1 W/dalvikvm? VFY: unable to resolve virtual method 8393: Landroid/support/v7/app/AppCompatActivity;.onCreate (Landroid/os/Bundle;Landroid/os/PersistableBundle;)V
08-20 10:53:23.605  24192-24192/com.mkapp.apps.demo1 D/dalvikvm? VFY: replacing opcode 0x6f at 0x0000
Run Code Online (Sandbox Code Playgroud)

我的依赖:

    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.google.android.gms:play-services:7.3.0'
    compile 'com.android.support:appcompat-v7:22.1.0+'
    compile 'com.android.support:multidex:1.0.1'
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助

从AppcompatActivity继承的旧活动可以正常工作.但如果我创建新的,它会得到错误.这是我的gradle.build:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.mkapp.apps.demo1"
        minSdkVersion 10
        targetSdkVersion 22
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
        multiDexEnabled true
    }
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile project(':photocollage')
    compile project(':gWFacebookSDK')
//    compile project(':listViewAnimation')
    compile 'com.google.android.gms:play-services:7.3.0'
    compile 'com.android.support:appcompat-v7:22.1.0'

    compile 'com.android.support:multidex:1.0.1'
    compile files('libs/aws-android-sdk-2.1.0-core.jar')
    compile files('libs/aws-android-sdk-2.1.0-sns.jar')
    compile files('libs/dexmaker-1.1.jar')
    compile files('libs/dexmaker-mockito-1.1-custom.jar')
//    compile files('libs/listviewanimations_lib-core_3.1.0.jar')
    compile files('libs/signpost-commonshttp4-1.2.1.1.jar')
    compile files('libs/signpost-core-1.2.1.1.jar')
    compile files('libs/signpost-jetty6-1.2.1.1.jar')
    compile files('libs/twitter4j-core-4.0.1.jar')
    compile files('libs/universal-image-loader-1.9.3.jar')
}
Run Code Online (Sandbox Code Playgroud)

Mat*_*ini 16

您遇到此问题是因为您尝试使用onCreate(Bundle savedInstanceState,PersistableBundle persistentState),但此方法仅适用于API级别21.

我能够在Android 4.4上重现此示例代码的问题:

public class TourActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState, new PersistableBundle());
    }

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
    }
}
Run Code Online (Sandbox Code Playgroud)

并解决了以下问题PersistableBundle:

public class TourActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}
Run Code Online (Sandbox Code Playgroud)

检查要使用PersistableBundle在你TourActivity并删除它,或与您的活动代码更新你的答案.


Jar*_*ler 12

更新您的支持库来23和你compileSdkVersion23的的build.gradle.

compileSdkVersion 23

...

compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
Run Code Online (Sandbox Code Playgroud)

然后使用gradle文件同步项目.

此外,Google Play服务现在也是 7.8.0


Art*_*uro 5

问题是您TourActivity使用的是只能从API级别21 PersistableBundle获得的类.这里的问题是为什么这样做.

请记住,您的新活动也必须继承AppCompatActivity.

快速问题,你是否压倒public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState)有问题的活动?如果您这样做,您可能正在保存PersistableBundle设备/模拟器中没有的引用.如果你没有在那里做任何事情,请尝试删除它或评论它尝试...