0

my app is working fine in android version 5.0 and app but in 4.4 im getting error.

here is the error

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

i use navigation drawer

here is my 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>

the error is in this part of my code.

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

anyone can help me to fix this error.

thanks

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Joe
  • 387
  • 1
  • 7
  • 22

1 Answers1

0

I found a question quite similar to this. It has been solved by lot of people in different ways , so I guess there is no one way to solve this.

I have triaged many solutions , some things which you can check is :

  1. NavigationDrawerFragment extending import android.support.v4.app.Fragment;
  2. Your Android Manifest has <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  3. If using actionBar activity , check its import :

Instead of this :

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

Use this :

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

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

There are other ways too , do checkout answers in that post.

Anonymous
  • 2,184
  • 15
  • 23
  • still not working.. the error is in this part of the code.. protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); – Joe Apr 18 '18 at 11:15
  • Is your NavigationDrawerFragment extending import android.support.v4.app.Fragment; – Anonymous Apr 18 '18 at 11:30