我遇到inflate exception
与AppCompatTextView
的问题,这是由类未发现异常引起的。 only at my third activity
发生此异常。即使此类也处于第一和第二活动中。我已经阅读过possible solutions like: clean and Rebuild my project,uninstall and reinstall app on emulator,disable instant Run (it's not possible considering my Android Studio version), enable Multidex
,但这些解决方案似乎都不适合我。
感谢您的帮助
我的logcat是...
08-01 22:04:31.500 15991-15991/com.fornapp.wordgame E/AndroidRuntime﹕
FATAL EXCEPTION: main
Process: com.fornapp.wordgame, PID: 15991
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fornapp.wordgame/com.fornapp.wordgame.Game}: android.view.InflateException: Binary XML file line #124: Binary XML file line #124: Error inflating class AppCompatTextView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #124: Binary XML file line #124: Error inflating class AppCompatTextView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Activity.setContentView(Activity.java:2166)
at com.fornapp.wordgame.Game.onCreate(Game.java:311)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.view.InflateException: Binary XML file line #124: Error inflating class AppCompatTextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Activity.setContentView(Activity.java:2166)
at com.fornapp.wordgame.Game.onCreate(Game.java:311)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.AppCompatTextView" on path: DexPathList[[zip file "/data/app/com.fornapp.wordgame-2/base.apk"],nativeLibraryDirectories=[/data/app/com.fornapp.wordgame-2/lib/x86_64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.view.LayoutInflater.createView(LayoutInflater.java:583)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:677)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:694)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:762)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Activity.setContentView(Activity.java:2166)
at com.fornapp.wordgame.Game.onCreate(Game.java:311)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.ClassNotFoundException: android.view.AppCompatTextView
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 29 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
这是包含AppCompatTextView的布局:
<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:animateLayoutChanges="true"
android:id="@+id/Flipper">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container"
android:animateLayoutChanges="true"
android:background="@drawable/gradient_background"
android:descendantFocusability="blocksDescendants"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.AppCompatTextView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="0.50"
app:layout_constraintHeight_percent="0.10"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:singleLine="true"
app:autoSizeTextType="uniform"
android:id="@+id/playMode"
android:background="@android:color/transparent"
style="@style/titles"
android:padding="4dp"/>
<android.support.v7.widget.AppCompatImageView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="0.10"
app:layout_constraintHeight_percent="0.05"
android:layout_gravity="center_horizontal"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:id="@+id/cup"
app:srcCompat="@drawable/cup"
/>
<android.support.v7.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/cup"
android:textColor="@color/white"
app:autoSizeTextType="uniform"
android:id="@+id/topScore"/>
<GridView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.12"
android:padding="1dp"
android:elevation="6dp"
android:id="@+id/to_guess"
android:gravity="center"
android:background="@drawable/bordergrid"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.50"
android:id="@+id/frame"
android:gravity="center">
<ProgressBar
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:max="1000"
android:layoutDirection="ltr"
android:progress="1000"
android:progressDrawable="@drawable/circle_progress"
android:secondaryProgress="1000"
android:id="@+id/progress_circular"
/>
<GridView
android:layout_width="112dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:columnWidth="50dp"
android:animateLayoutChanges="true"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp"
android:horizontalSpacing="8dp"
android:id="@+id/to_choose">
</GridView>
</FrameLayout>
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.20"
android:id="@+id/graphic_lives"
app:srcCompat="@drawable/three_lives"
android:layout_gravity="center_horizontal"/>
</android.support.constraint.ConstraintLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/SceneFromLevelToLevel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_background">
<AppCompatTextView
android:id="@+id/StringLevelComplete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:textColor="@color/white"
android:textSize="30sp"
android:textStyle="bold"
android:layout_centerInParent="true"
/>
<android.support.v7.widget.AppCompatImageView
android:id="@+id/ImageLevelComplete"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_above="@id/StringLevelComplete"
android:layout_marginBottom="48dp"
android:paddingLeft="24dp"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/cartel"/>
<android.support.v7.widget.AppCompatImageButton
android:id="@+id/NextButton"
android:layout_below="@id/StringLevelComplete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="24dp"
android:layout_marginTop="24dp"
android:layout_alignParentRight="true"
android:background="@drawable/round_button_border"
app:srcCompat="@drawable/forward"/>
</RelativeLayout>
</ViewFlipper>
这是我的模块Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.fornapp.wordgame"
vectorDrawables.useSupportLibrary = true
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-core-ui:26.1.0'
compile 'com.android.support:support-core-utils:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.1.0'
compile 'com.google.android.gms:play-services-ads:11.8.0'
}
那是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fornapp.wordgame" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="ANDROID.PERMISSION.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".OptionsActivity"
android:label="@string/title_options"
android:configChanges="orientation|screenSize">
</activity>
<activity android:name=".Game" android:configChanges="orientation|screenSize" />
<activity android:name=".EndGame" android:configChanges="orientation|screenSize"/>
</application>
</manifest>