android.support.v7.view.SupportMenuInflater.parseMenu;意外的文件结束

时间:2017-03-17 05:17:34

标签: android android-support-library android-design-library androiddesignsupport

我正在使用内置导航活动(activity->导航抽屉活动)。

到目前为止工作正常,但现在我收到错误消息

   com.focus.abhishek.ftouchutility, PID: 2119
       java.lang.RuntimeException: Unable to start activity ComponentInfo{com.focus.abhishek.ftouchutility/com.focus.abhishek.ftouchutility.ModulesActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
       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 #16: 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.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                                at com.focus.abhishek.ftouchutility.ModulesActivity.onCreate(ModulesActivity.java:46)
                                                                                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 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.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                at com.focus.abhishek.ftouchutility.ModulesActivity.onCreate(ModulesActivity.java:46) 
                                                                                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.RuntimeException: Unexpected end of document
                                                                                at android.support.v7.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:205)
                                                                                at android.support.v7.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118)
                                                                                at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:246)
                                                                                at android.support.design.widget.NavigationView.<init>(NavigationView.java:171)
                                                                                at android.support.design.widget.NavigationView.<init>(NavigationView.java:97)
                                                                                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.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                                                                                at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                                at com.focus.abhishek.ftouchutility.ModulesActivity.onCreate(ModulesActivity.java:46) 
                                                                                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)

即:错误发生在我的主要活动

setContentView(R.layout.activity_modules);

这是activity_modules xml:

<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_modules"
    app:menu="@menu/activity_modules_drawer" />

的build.gradle

  android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
    applicationId "com.focus.abhishek.ftouchutility"
    minSdkVersion 14
    targetSdkVersion 24
    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:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.squareup.okhttp3:okhttp:3.6.0'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
testCompile 'junit:junit:4.12'
compile 'com.daimajia.numberprogressbar:library:1.4@aar'
}

Style.xml

   <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="toolbarStyle">@style/Widget.AppCompat.Toolbar</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="ToolbarTitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
    <item name="android:textSize">20sp</item>
</style>

<style name="AppTheme.NoActionBar.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.NoActionBar.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

@菜单/ activity_modules_drawer:

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_allocation"
            android:icon="@drawable/nav_allocation"
            android:title="@string/nav_Allocation" />
        <item
            android:id="@+id/nav_tracker"
            android:icon="@drawable/nav_tracker"
            android:title="@string/nav_Tracker" />

        <item
            android:id="@+id/nav_sync"
            android:icon="@drawable/nav_sync"
            android:title="@string/nav_Sync" />

        <item
            android:id="@+id/nav_upload_doc"
            android:icon="@drawable/ic_menu_gallery"
            android:title="@string/nav_Upload" />

        <item
            android:id="@+id/nav_pending_upload"
            android:icon="@drawable/pending_upload"
            android:title="@string/nav_Upload_pending" />
    </group>


        <menu>
            <item
                android:id="@+id/nav_profile"
                android:icon="@drawable/nav_profile"
                android:title="@string/nav_Profile" />
            <item
                android:id="@+id/nav_change_pass"
                android:icon="@drawable/nav_changepass"
                android:title="@string/nav_Change_pass" />

            <item
                android:id="@+id/nav_Logout"
                android:icon="@drawable/nav_logout"
                android:title="@string/nav_Logout" />
        </menu>

</menu>

2 个答案:

答案 0 :(得分:3)

如果你只是学习阅读logcat,你会看到......

 Caused by: java.lang.RuntimeException: Unexpected end of document
        at android.support.v7.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:205)
        at android.support.v7.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118)

所以,你看到菜单 Inflater,这在你的XML中有错误

@menu/activity_modules_drawer

所以你打开那个文件,你看看它。

您有两个<menu>代码,但该文件中只有一个代码,因此您有一个意外的文档结尾

试试这个固定的。

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_allocation"
            android:icon="@drawable/nav_allocation"
            android:title="@string/nav_Allocation" />
        <item
            android:id="@+id/nav_tracker"
            android:icon="@drawable/nav_tracker"
            android:title="@string/nav_Tracker" />

        <item
            android:id="@+id/nav_sync"
            android:icon="@drawable/nav_sync"
            android:title="@string/nav_Sync" />

        <item
            android:id="@+id/nav_upload_doc"
            android:icon="@drawable/ic_menu_gallery"
            android:title="@string/nav_Upload" />

        <item
            android:id="@+id/nav_pending_upload"
            android:icon="@drawable/pending_upload"
            android:title="@string/nav_Upload_pending" />
    </group>


    <item
        android:id="@+id/nav_profile"
        android:icon="@drawable/nav_profile"
        android:title="@string/nav_Profile" />
    <item
        android:id="@+id/nav_change_pass"
        android:icon="@drawable/nav_changepass"
        android:title="@string/nav_Change_pass" />

    <item
        android:id="@+id/nav_Logout"
        android:icon="@drawable/nav_logout"
        android:title="@string/nav_Logout" />

</menu>

答案 1 :(得分:0)

抽屉的典型菜单项看起来像这样

<div class="help">
  <input type="text" >
  <a href=""></a>
</div>

找出你的错误