gpt4 book ai didi

java - 空白 Android Activity 上未找到类错误

转载 作者:行者123 更新时间:2023-12-01 21:40:27 28 4
gpt4 key购买 nike

当我在 Android Studio 2.0 中创建一个空白 Activity 并尝试在 API 16 上运行它时,它编译时没有错误。当我在具有 API 23 的模拟器上运行它时,它运行时没有错误。当我在 API 16 上运行它时,应用程序启动时会出现一堆错误。见下文。奇怪的是应用程序运行正常。

这可能是什么原因造成的?

在 Android Studio 中,我使缓存失效并清除。还清理了项目并重建了它。

引用代码:

AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="nl.myapp.test">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

MainActivity.Java

package nl.myapp.test;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="nl.myapp.test.MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>

Gradle 2.0.0 构建文件 build.gradle(模块应用程序)

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "nl.myapp.test"
minSdkVersion 16
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.3.0'
}

应用在 API 16 上启动时出现 logcat 错误

04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.transition.TransitionManager', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.UserHandle', referenced from method nl.myapp.test.MainActivity.access$super
04-10 18:29:29.945 23899-23899/nl.myapp.test E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method nl.myapp.test.MainActivity.access$super

最佳答案

您的应用可能达到了 64k 方法的限制。您的应用程序的 API 级别 21 及以下会出现此问题。请参阅document 。它提供了有关该问题的详细信息以及如何使用 Multidex 支持库为旧版本的 Android 解决该问题。

还有this可能是问题的快速解决方案。

关于java - 空白 Android Activity 上未找到类错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36532557/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com