Runtime exception: error inflating android.support.v4.widget.DrawerLayout class

I am getting a bloat error on the android.support.v4.widget.DrawerLayout class. I have posted a detailed description in the following encodings and corresponding screenshots.

StackTrace:

11-04 07:35:04.404: E/AndroidRuntime(1427): FATAL EXCEPTION: main
11-04 07:35:04.404: E/AndroidRuntime(1427): Process: com.example.steve, PID: 1427
11-04 07:35:04.404: E/AndroidRuntime(1427): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.steve/com.example.steve.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.widget.DrawerLayout
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.os.Handler.dispatchMessage(Handler.java:102)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.os.Looper.loop(Looper.java:136)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.main(ActivityThread.java:5017)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at java.lang.reflect.Method.invokeNative(Native Method)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at java.lang.reflect.Method.invoke(Method.java:515)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at dalvik.system.NativeStart.main(Native Method)
11-04 07:35:04.404: E/AndroidRuntime(1427): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.v4.widget.DrawerLayout
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.Activity.setContentView(Activity.java:1929)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at com.qrme.quranmadeeasy.ChapterActivity.onCreate(ChapterActivity.java:91)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.Activity.performCreate(Activity.java:5231)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-04 07:35:04.404: E/AndroidRuntime(1427):     ... 11 more
11-04 07:35:04.404: E/AndroidRuntime(1427): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.widget.DrawerLayout" on path: DexPathList[[zip file "/data/app/com.qrme.quranmadeeasy-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.qrme.quranmadeeasy-2, /system/lib]]
11-04 07:35:04.404: E/AndroidRuntime(1427):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
11-04 07:35:04.404: E/AndroidRuntime(1427):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
11-04 07:35:04.404: E/AndroidRuntime(1427):     ... 20 more

      

ChapterActivity.java:

package com.example.steve;

import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;

public class MainActivity extends Activity implements OnItemClickListener {

RelativeLayout relativelayoutContainer;
    TextView txtHeading;
    ListView listChapter;
    ListView listSlider;
    ImageView imgBanner;

@SuppressLint("NewApi")
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        setContentView(R.layout.activity_main); --->Error line no.91
        initialize();
     }
     private void initialize() {


    relativelayoutContainer = (RelativeLayout) findViewById(R.id.container);
    txtHeading = (TextView) findViewById(R.id.textviewHeading);
    listChapter = (ListView) findViewById(R.id.listviewChapters);
    imgBanner = (ImageView) findViewById(R.id.imageviewBanner);
    listSlider = (ListView) findViewById(R.id.list_slidermenu);

    // Setting font color and size
    Resources resources = ChapterActivity.this.getResources();
     }

    private void displayView(int position) {
        // update the main content by replacing fragments
        Fragment fragment = null;
        switch (position) {
        case 0:
            fragment = new HomeFragment();
            break;
        case 1:
            fragment = new FindPeopleFragment();
            break;
        case 2:
            fragment = new PhotosFragment();
            break;

        default:
            break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.frame_container, fragment).commit();

            // update selected item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(navMenuTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);
        } else {
            // error in creating fragment
            Log.e("MainActivity", "Error in creating fragment");
        }
    }
  }

      

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
  <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

     <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <RelativeLayout
        android:id="@+id/container"
        android:layout_width="match_parent"layout_width="wrap_content"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/textviewHeading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:fontFamily="fonts/Dosis.otf"
            android:text="@string/heading_chapter"
            android:textSize="25sp"
            android:visibility="gone" />

        <ListView
            android:id="@+id/listviewChapters"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/imageviewBanner"
            android:layout_below="@+id/textviewHeading"
            android:layout_marginTop="5dp" />
        </ListView>

        <ImageView
            android:id="@+id/imageviewBanner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:src="@drawable/banner"
            android:visibility="invisible" />
    </RelativeLayout>


    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
    android:background="@color/list_background"
    android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"        
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>

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

      

If I click on Graphic Layout I get this below. An exception:

enter image description here

Exception raised during rendering: com.android.layoutlib.bridge.MockView cannot be cast to android.view.ViewGroup
Exception details are logged in Window > Show View > Error Log
The following classes could not be instantiated:
- android.support.v4.widget.DrawerLayout (Open Class, Show Error Log)

      

Then, in the Java path the BuildLibrary

enter image description here

Then, in the Java Build Pathorder and export :

enter image description here

In the above screenshot, if I do check

android.support.v4.jar

, I get the following Multiple Dex error in the console:

[2014-11-04 18:35:30 - Dex Loader] Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
[2014-11-04 18:35:30 - main-android] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;

      

enter image description here

+3


source to share


5 answers


Just check Android and support lib box, it will solve your problem.



+11


source


If I understand correctly, you just need to invoke the new action directly when you select an option in the ListView (and abandon it entirely GalleryFragment

). Something like:

private void displayView(int position) {
    if (position == 0) {
        Intent i = new Intent(getActivity(), GalleryActivity.class);
        startActivity(i);
        return
    }

    // ... same as before, for the other fragments

      



It is not necessary to display fragments when clicking on the box options.

0


source


1.)If it is showing multiple dex file, then remove v4 library 

2.)Show us which project you are adding as a library in this project and in that check the v4 library

3.)Clean the project from Project -> clean and run the project

      

0


source


User @Dev Suggested me how to use the box layout and where the error occurred in them. So I can solve this problem.

Runtime exception: bloat error for android.support.v4.widget.DrawerLayout class :

  • This error occurred due to an incorrect implementation of the box layout. I am placing three direct children in the drawer layout an error will occur. According to DrawerLayout, it took two children directly.

  • In the drawer layout, if I placed two straight layouts solved the problem. So I use Frame Layout as parent layout inside Layer Layout then finally add list view after frame layout to display drawer navigation.

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:id="@+id/container"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/textviewHeading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="5dp"
                android:fontFamily="fonts/Dosis.otf"
                android:text="@string/heading_chapter"
                android:textSize="25sp"
                android:visibility="gone" />

            <ListView
                android:id="@+id/listviewChapters"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/imageviewBanner"
                android:layout_below="@+id/textviewHeading"
                android:layout_marginTop="5dp" >
            </ListView>

            <ImageView
                android:id="@+id/imageviewBanner"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:src="@drawable/banner"
                android:visibility="invisible" />
        </RelativeLayout>
    </FrameLayout>

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@color/list_background"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

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

      

Unable to execute dex: multiple dex files define :

  • This error happened due to android-v4.jar support. This jar has not been updated in my project. It's almost 325 kilobytes in size. So I have to test the jar with another sample application. In this sample application, the jar size will be 530 kb. Then I find it qmr project jar was a bug. This is not an updated bank. So I removed the jar hosted in qmr and added the sample jar project.Then it solved my problem.

  • The error occurs if I put the jar in this directory (E:\Android Eclipse\Android\sdk\extras\android\support\v4)

    . This Directory is applicable for adding a jar. But not in my project.

  • Since other jars like gson.jar libgoogleanalytics.jar have a directory in E:\workspace\Workspace1\sample-android\libs.

    So in my project add a jar in the same directory to solve my problem

0


source


yes i solved your problem simply

Right click on Project
Build Path -> Configure Build Path
add your external support v4 
then check the support v4 from order and export

Make sure your Android and Android Dependencies libraries are checked
Clean & Build your Project

      

I think this will solve your problem.

0


source







All Articles