【问题标题】:getting error in OS version 4.4在操作系统版本 4.4 中出现错误
【发布时间】:2018-04-18 10:26:47
【问题描述】:

我的应用在 android 版本 5.0 和应用中运行良好,但在 4.4 中出现错误。

这是错误

04-18 18:10:50.575 19764-19764/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.administrator.mosbeau, PID: 19764
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.administrator.mosbeau/com.example.administrator.mosbeau.MainActivity}: android.view.InflateException: Binary XML file line #43: Error inflating class android.support.v7.widget.ActionBarContextView

我使用导航抽屉

这是我的 activity_main.xml

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
    android:layout_width="match_parent" android:layout_height="match_parent"
    tools:context=".MainActivity">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout android:id="@+id/container" android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         If you're not building against API 17 or higher, use
         android:layout_gravity="left" instead. -->
    <!-- The drawer is given a fixed width in dp and extends the full height of
         the container. -->
    <fragment android:id="@+id/navigation_drawer"
    android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent"
    android:layout_gravity="start"
    android:name="com.example.administrator.mosbeau.NavigationDrawerFragment"
    tools:layout="@layout/fragment_navigation_drawer" />



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

错误出现在我的这部分代码中。

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

任何人都可以帮我解决这个错误。

谢谢

【问题讨论】:

  • 对我来说工作得很好,你的 android:name 在 标签中正确吗?
  • 是的,android:name 是正确的。

标签: android inflate-exception


【解决方案1】:

我发现了一个与此非常相似的question。已经解决了很多 人们以不同的方式,所以我想没有一种方法可以解决这个问题。

我已经对许多解决方案进行了分类,您可以检查一些事情是:

  1. NavigationDrawerFragment 扩展 import android.support.v4.app.Fragment;
  2. 您的Android Manifest&lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  3. 如果使用 actionBar 活动,请检查其导入:

而不是这个:

import android.app.Activity;
import android.app.ActionBar;

使用这个:

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
  1. 检查 build.gradle :

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

还有其他方法,在那个帖子中检查答案。

【讨论】:

  • 仍然无法正常工作..错误在这部分代码中.. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
  • 你的 NavigationDrawerFragment 是否在扩展 import android.support.v4.app.Fragment;
猜你喜欢
  • 2016-08-22
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
  • 2012-02-05
  • 2019-09-02
  • 1970-01-01
  • 1970-01-01
  • 2014-08-21
相关资源
最近更新 更多