应用程序在模拟器中运行但在设备中运行

时间:2017-01-17 04:16:54

标签: android

我有一个使用主页基本布局的应用程序。

布局:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer"/>
    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.v4.widget.DrawerLayout> 

Gradle文件:

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "com.ramyoogesh.android.navigationtest"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    testCompile 'junit:junit:4.12'
}

当我在Marshmallow模拟器中运行应用程序时,它运行正常。但是,当我尝试在我的KitKat设备中运行应用程序时,它会开始抛出此错误:

01-17 09:39:59.788 3661-3661/com.ramyoogesh.android.navigationtest E/AndroidRuntime: FATAL EXCEPTION: main
 Process: com.ramyoogesh.android.navigationtest, PID: 3661
 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ramyoogesh.android.navigationtest/com.ramyoogesh.android.navigationtest.MainActivity}: android.view.InflateException: Binary XML file line #41: Error inflating class android.support.design.widget.NavigationView
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
     at android.app.ActivityThread.access$800(ActivityThread.java:151)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
     at android.os.Handler.dispatchMessage(Handler.java:110)
     at android.os.Looper.loop(Looper.java:193)
     at android.app.ActivityThread.main(ActivityThread.java:5292)
     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:824)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
     at dalvik.system.NativeStart.main(Native Method)
  Caused by: android.view.InflateException: Binary XML file line #41: Error inflating class android.support.design.widget.NavigationView
     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
     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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
     at com.ramyoogesh.android.navigationtest.MainActivity.onCreate(MainActivity.java:31)
     at android.app.Activity.performCreate(Activity.java:5264)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
     at android.os.Handler.dispatchMessage(Handler.java:110) 
     at android.os.Looper.loop(Looper.java:193) 
     at android.app.ActivityThread.main(ActivityThread.java:5292) 
     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:824) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
     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 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
     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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136) 
     at com.ramyoogesh.android.navigationtest.MainActivity.onCreate(MainActivity.java:31) 
     at android.app.Activity.performCreate(Activity.java:5264) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
     at android.os.Handler.dispatchMessage(Handler.java:110) 
     at android.os.Looper.loop(Looper.java:193) 
     at android.app.ActivityThread.main(ActivityThread.java:5292) 
     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:824) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
     at dalvik.system.NativeStart.main(Native Method) 
  Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f02005a
     at android.content.res.Resources.getValue(Resources.java:1133)
     at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:320)
     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:196)
     at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
     at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
     at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:495)
     at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:436)
     at android.support.design.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:112)
     at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:245)
     at android.support.design.widget.NavigationView.<init>(NavigationView.java:169)
     at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
     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 android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
     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.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136) 
     at com.ramyoogesh.android.navigationtest.MainActivity.onCreate(MainActivity.java:31) 
     at android.app.Activity.performCreate(Activity.java:5264) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390) 
     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
     at android.os.Handler.dispatchMessage(Handler.java:110) 
     at android.os.Looper.loop(Looper.java:193) 
     at android.app.ActivityThread.main(ActivityThread.java:5292) 
     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:824) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 
     at dalvik.system.NativeStart.main(Native Method) 

我猜测XML或gradle文件中肯定存在一些错误。我尝试将appcompat-v7更改为各种版本,但错误仍然存​​在。

1 个答案:

答案 0 :(得分:0)

我认为您使用的是VectorDrawable,并且您没有以Kitkat支持的方式实现它。只需检查您的nav_header_main布局,如果您使用vectorDrawable,请在lollipop下方查看link如何支持它。