Android 应用程序无法在 4.0 中工作,但可以在 5+ 上工作 错误膨胀类 android.support.design.widget.NavigationView

2024-05-04

一旦在 5.0+ 版本中运行我的应用程序,它就可以很好地工作。但对于较低版本,它会给我错误并且无法打开。

这是我收到的错误:

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

  1. 引起原因:android.view.InflateException:二进制 XML 文件第 17 行:错误膨胀类 android.support.design.widget.NavigationView
  2. 引起原因:java.lang.reflect.InitationTargetException
  3. 引起原因:android.content.res.Resources$NotFoundException:资源 ID #0x7f020052
  4. 在 lk.myoffers.app.myofferslk.MainActivity.onCreate(MainActivity.java:84)

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

我是 Android 新手,请问问题出在哪里?

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;

My 活动主线:

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

My Android 清单 file:

<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 我有以下代码行

<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 版本集

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

The 最低版本 is 23.

这是我的 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 我已经通过删除检查了导航视图

  • 应用程序:headerLayout =“@layout / nav_header_main”

  • 应用程序:菜单=“@menu/activity_main_drawer”

这两行分别并检查 android 监视器是否有错误

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

去除应用程序:headerLayout =“@layout / nav_header_main”不做任何改变给我同样的错误

但去掉后应用程序:菜单=“@menu/activity_main_drawer”应用程序工作正常,加载左侧导航,没有菜单项。正如你在我的错误列表中看到的那样引起原因:android.content.res.Resources$NotFoundException:资源 ID #0x7f020052

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

<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 可能从菜单图标之一升起。 终于对我有用了!感谢大家的大力支持

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 应用程序无法在 4.0 中工作,但可以在 5+ 上工作 错误膨胀类 android.support.design.widget.NavigationView 的相关文章

随机推荐