我正在使用android studio 3.2.1和运行android 7.0.0或更高版本的应用。但是当我在较低版本的模拟器或4.4.4或5.1.1等设备中运行它时,由于以下错误而崩溃,并说无法启动活动
10-24 07:26:22.936 1630-1630/com.gcc.drt_driver E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.gcc.drt_driver, PID: 1630
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gcc.drt_driver/com.gcc.drt_driver.activities.Login}: android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.gcc.drt_driver.activities.Login.onCreate(Login.java:41)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.gcc.drt_driver.activities.Login.onCreate(Login.java:41)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f07005e a=-1 r=0x7f07005e}
at android.content.res.Resources.loadDrawable(Resources.java:2068)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3554)
at android.view.ViewGroup.<init>(ViewGroup.java:470)
at android.widget.LinearLayout.<init>(LinearLayout.java:176)
at android.widget.LinearLayout.<init>(LinearLayout.java:172)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.gcc.drt_driver.activities.Login.onCreate(Login.java:41)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
10-24 07:26:23.856 804-804/com.android.launcher E/EGL_emulation: tid 804: eglSurfaceAttrib(1210): error 0x3009 (EGL_BAD_MATCH)
10-24 07:26:24.004 610-755/system_process I/ActivityManager: Killing 1296:com.android.exchange/u0a30 (adj 15): empty #17
10-24 07:26:31.380 610-625/system_process E/WindowManager: Starting window AppWindowToken{529afe08 token=Token{529640c0 ActivityRecord{52860098 u0 com.gcc.drt_driver/.activities.Login t2}}} timed out
我的gradle文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 26
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.gcc.drt_driver"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "drt_driver-v${variant.versionName}.apk"
}
}
}
}
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:26.1.0'
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.+'
//implementation 'com.facebook.android:account-kit-sdk:4.30.0'
implementation 'com.android.support:mediarouter-v7:26.+'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.google.android.gms:play-services-places:11.8.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.android.support:support-v4:26.1.0'
testImplementation 'junit:junit:4.12'
implementation 'com.google.maps:google-maps-services:0.1.20'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.android.support:recyclerview-v7:26.+'
implementation 'com.android.support:cardview-v7:26.+'
implementation 'com.joooonho:selectableroundedimageview:1.0.1'
implementation 'com.facebook.stetho:stetho:1.5.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
implementation "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
kapt "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
implementation 'com.android.support:multidex:1.0.3'
}
repositories {
mavenCentral()
}
和清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gcc.drt_driver">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name="android.support.multidex.MultiDexApplication"
android:theme="@style/AppTheme">
<activity android:name=".activities.Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activities.Dashboard"
android:label="@string/title_activity_dashboard"
android:theme="@style/AppTheme" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBKmFxyacVaTHpBnab1iR0_y_GN_LYjGNc" />
<activity android:name=".activities.TripList" />
<activity android:name=".activities.TripHistory" />
<activity android:name=".activities.PassengerList"></activity>
</application>
</manifest>
以及类似的login.xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<!--<ImageView-->
<!--android:id="@+id/logo_image"-->
<!--android:layout_width="120dp"-->
<!--android:layout_height="120dp"-->
<!--android:src="@drawable/login_logo"-->
<!--android:layout_centerHorizontal="true"-->
<!--android:layout_marginTop="50dp"-->
<!--/>-->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/border"
android:orientation="vertical">
<TextView
android:id="@+id/text_view_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:textSize="25sp"
android:textColor="@color/colorLoginTxt"
android:ems="12"
android:text="LOGIN" />
<android.support.design.widget.TextInputLayout
android:id="@+id/usernameWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editTextLoginUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_below="@+id/customView"
android:ems="12"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:hint="@string/user_name_hint"
android:inputType="textNoSuggestions" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/passwordWapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editTextLoginPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_below="@+id/editTextLoginUser"
android:ems="12"
android:hint="@string/user_password_hint"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/buttonSignIn"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_marginTop="40dp"
android:layout_below="@+id/editTextLoginPassword"
android:layout_marginBottom="20dp"
android:layout_gravity="center"
android:onClick="performLogin"
android:text="@string/login_btn"
android:textSize="15sp"
android:textColor="#fff"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/regView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="30dp">
<!--<TextView-->
<!--android:id="@+id/text_reg"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_marginTop="0dp"-->
<!--android:layout_marginLeft="5dp"-->
<!--android:layout_gravity="center"-->
<!--android:textSize="18sp"-->
<!--android:onClick="performReg"-->
<!--android:textColor="@color/colorRegTxt"-->
<!--android:text="@string/reg_btn" />-->
<!--<TextView-->
<!--android:id="@+id/text_forgetPass"-->
<!--android:layout_height="wrap_content"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_marginTop="0dp"-->
<!--android:layout_marginLeft="5dp"-->
<!--android:layout_gravity="center"-->
<!--android:textSize="18sp"-->
<!--android:onClick="forgetPassword"-->
<!--android:textColor="@color/colorRegTxt"-->
<!--android:text="@string/forget_pass_btn" />-->
</LinearLayout>
</LinearLayout>
<!--<ImageView-->
<!--android:id="@+id/loadSyncDataIv"-->
<!--android:layout_width="55dp"-->
<!--android:layout_height="55dp"-->
<!--android:layout_margin="15dp"-->
<!--android:layout_alignParentBottom="true"-->
<!--android:clickable="true"-->
<!--android:src="@drawable/load"-->
<!--android:layout_alignParentEnd="true" />-->
</RelativeLayout>
有人有解决方案吗?
我的border.xml是
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="3dp" android:color="#B1BCBE" />
<corners android:radius="10dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>
答案 0 :(得分:0)
您需要在drawable-v21中添加您的drawable资源。