在空白的Android活动上找不到类错误 [英] Class not found errors on blank Android Activity
问题描述
当我在Android Studio 2.0中创建空白活动并尝试在API 16上运行该活动时,它将正确编译.当我在具有API 23的仿真器上运行它时,它运行无误.当我在API 16上运行它时,在应用启动时会给我很多错误.见下文.奇怪的是,该应用程序运行正常.
When I create a blank activity in Android Studio 2.0 and try to run it on API 16 it compiles without errors. When I run it on an emulator with API 23 it runs without errors. When I run it on API 16 it gives me a bunch of errors when the app starts. See below. The weird thing is that the app runs OK.
这可能是什么原因?
在Android Studio中,我无效并清除了缓存.还清理了项目并重建了它.
In Android Studio I invalidated and cleared the cache. Also cleaned the project and rebuilt it.
代码以供参考:
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>
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
推荐答案
在Android Studio中,我转到了文件->项目结构->项目.
In Android Studio I went to File -> Project Structure -> Project.
首先,我将Gradle升级到 2.11 ,并将Android插件版本升级到 2.0.0 . 接下来,我同步了项目并对其进行了编译.错误仍然存在.
First I upgraded Gradle to 2.11 and the Android Plugin Version to 2.0.0. Next I synced the project and compiled it. The errors were still there.
此后,我将Android插件版本降级为 1.5.0 .
After this I downgraded the Android Plugin Version to 1.5.0.
现在,当我编译并运行项目时,错误消失了.
Now when I compile and run the project the errors are gone.
这篇关于在空白的Android活动上找不到类错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!