Android应用程式无法在4.0中运作,但适用于5以上版本的错误,导致类别android.support.design.widget.NavigationView膨胀 [英] Android App not working in 4.0 but working on 5+ Error inflating class android.support.design.widget.NavigationView

查看:107
本文介绍了Android应用程式无法在4.0中运作,但适用于5以上版本的错误,导致类别android.support.design.widget.NavigationView膨胀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦在5.0+版本中运行我的应用程序,它将运行良好.但是对于较低的版本,它会给我错误并且无法打开.

Once run my app in 5.0+ versions it working nicely. but for lower version it gives me errors and not opening up.

这是我得到的错误:

无法启动活动ComponentInfo {lk.myoffers.app.myofferslk/lk.myoffers.app.myofferslk.MainActivity}:android.view.InflateException:二进制XML文件第17行:膨胀类android.support.design的错误. widget.NavigationView

Unable to start activity ComponentInfo{lk.myoffers.app.myofferslk/lk.myoffers.app.myofferslk.MainActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.NavigationView

  1. 原因:android.view.InflateException:二进制XML文件第17行:膨胀类android.support.design.widget.NavigationView时出错
  2. 由以下原因引起:java.lang.reflect.InvocationTargetException
  3. 原因:android.content.res.Resources $ NotFoundException:资源ID#0x7f020052
  4. 在lk.myoffers.app.myofferslk.MainActivity.onCreate(MainActivity.java:84)上
  1. Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.widget.NavigationView
  2. Caused by: java.lang.reflect.InvocationTargetException
  3. Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020052
  4. at lk.myoffers.app.myofferslk.MainActivity.onCreate(MainActivity.java:84) 

我已经尝试了Stack Overflow上的所有方法,但是问题仍然存在.

I have tried every thing on Stack Overflow but the issue is still remaining.

我是android的新手,那么可能是什么问题?

I'm new to android, so what could be the issue?

setContentView(R.layout.activity_main);在第84行.

public class MainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener{


public static int pageCount = 1;

private int totalLoadedCount;
private AdListAdapter adapter;

TextView txtUserName;
Button btnReconnect;

private static String LIST_INSTANCE_STATE = "items";
private ArrayList<AdList> adLists = new ArrayList<AdList>();

private ArrayList<MasterCategory> mstCategory = new ArrayList<MasterCategory>();
private MasterCategoryAdapter catAdapter;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    totalLoadedCount = 0;

我的 activity_main :

<?xml version="1.0" encoding="utf-8"?>

<include
    layout="@layout/app_bar_main"
    android:id="@+id/aa"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<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"
    />

我的 Android清单文件:

<activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme1"
        android:configChanges="orientation|keyboardHidden|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

对于style.xml我有以下代码行

and for the style.xml i have following code lines

<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>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:button">@color/colorButton</item>
</style>

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">#673AB7</item>
    <item name="colorPrimaryDark">#512DA8</item>
    <item name="colorAccent">#00BCD4</item>
</style>

<style name="MIP_theme" parent="AppTheme">
    <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" />

我已经尝试了所有方法,但是在低于5的Android上无法正常工作 Gradle版本集

I have tried every thing, but it's not working on Android lower than 5 Gradle version set

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'

最低版本是23.

这是我的build.gradle

Here is my build.gradle

android {
compileSdkVersion 23
buildToolsVersion "24.0.1"
defaultConfig {
    applicationId "lk.myoffers.app.myofferslk"
    minSdkVersion 14
    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.4.0'
    compile 'com.android.support:design:23.4.0'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.github.darsh2:MultipleImageSelect:v0.0.4'
    compile 'com.loopj.android:android-async-http:1.4.9'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:cardview-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
}

推荐答案

最后几天是经过很多次调试之后 感谢#0X0nosugar,我已经通过删除来检查了Navigationview

Finally after many days and after doing many debugs thanks to #0X0nosugar I have checked the navigationview by removing

  • app:headerLayout ="@ layout/nav_header_main"

  • app:headerLayout="@layout/nav_header_main"

app:menu ="@ menu/activity_main_drawer

app:menu="@menu/activity_main_drawer

分别这两行,并检查android监视器中的错误

these two line separately and check the android monitor for errors

<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"
/>

删除 app:headerLayout ="@ layout/nav_header_main" 不会进行任何更改都会给我带来相同的错误

removing app:headerLayout="@layout/nav_header_main" doesn't make any changes gives me the same error

但是删除 app:menu ="@ menu/activity_main_drawer" 后,应用程序可以正常运行,并加载没有菜单项的左侧导航.因此,如您在我的错误列表中所看到的,它说原因:android.content.res.Resources $ NotFoundException:资源ID#0x7f020052

But after removing app:menu="@menu/activity_main_drawer" app works fine and load the left side navigation with no menu item. so as you can see in my error list it says Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020052

因此,我通过删除在res-> menu的activity_main_drawer中放置的菜单项中的自定义矢量图标进行检查.现在可以正常工作了.一个问题

So I checked by removing custom vector icons in menu item I placed in my activity_main_drawer in res->menu . Its now working fine. problem with a one

<item
            android:id="@+id/ic_menu_logout"
            android:icon="@drawable/change_this_icon_with_default_icon_comes_in_android"
            android:title="Logout"
            />
        <item

现在它可以正常工作..遇到此问题的每个人都请检查您的控制台.如果其显示"ResourceNotFoundException",则此错误会使类android.support.design.widget.NavigationView膨胀,可能是从菜单图标之一出现的. 终于对我有用!谢谢大家的大力支持

now its working fine.. Everyone who get this issue check your console. if its says "ResourceNotFoundException" this Error inflating class android.support.design.widget.NavigationView probably rising from one of the menu icon.. Finally Works for me! Thanks everyone for your great support

这篇关于Android应用程式无法在4.0中运作,但适用于5以上版本的错误,导致类别android.support.design.widget.NavigationView膨胀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆