0

i was working with Drawer Layout,and it was working perfect, it worked in api>14 before, but currently only works in my android Lollipop, i have not changed my gradle file, and when i run in a non lollipop device, it crash, the logcat is:

10-06 17:46:57.336  22668-22668/com.estratek.postreet E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.estratek.postreet/com.estratek.postreet.postreet_lib.activities.Home}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v4.widget.DrawerLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        at android.app.ActivityThread.access$600(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.v4.widget.DrawerLayout
        at android.view.LayoutInflater.createView(LayoutInflater.java:613)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
      at android.app.Activity.setContentView(Activity.java:1867)
        at com.estratek.postreet.postreet_lib.activities.Home.onCreate(Home.java:65)
        at android.app.Activity.performCreate(Activity.java:5008)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

            

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)

could you help me, i am missing something, my gradle file has the support libraries such as:

compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'

EDIT. And my XML layout is:

<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"
style="@style/postreet_theme"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".activities.Home" >

<!-- Framelayout to display Fragments -->
   <!-- style="@style/global_layout" -->

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

<!-- Listview to display slider menu -->

<ListView
    android:id="@+id/list_slidermenu"
    style="@style/offcanvas_areas"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:choiceMode="singleChoice"
    android:divider="@color/blue_light" />

Edit 2.

app gradle dependencies:

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.parse.bolts:bolts-android:1.+'
     compile 'com.android.support:multidex:1.0.0'
     compile 'com.astuetz:pagerslidingtabstrip:+'
     compile project(':backgroundmaillibrary')
     compile project(':filechooser');
     compile project(':snackbar');
     compile 'com.google.android.gms:play-services-maps:+'
     compile "com.google.android.gms:play-services-gcm:7.8.0"
     compile 'com.google.guava:guava:14.0.1'
     compile 'com.squareup.okhttp:okhttp:2.0.0'
     compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
     compile 'com.squareup.okio:okio:1.0.1'
     compile 'uk.co.chrisjenx:calligraphy:2.1.0'
     compile 'com.github.ksoichiro:simplealertdialog:1.2.1@aar'
     compile 'com.netflix.rxjava:rxjava-android:0.16.1'
     compile 'com.android.support:design:22.2.0'
     compile 'com.jakewharton:butterknife:7.0.1'
     androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
     compile 'ch.acra:acra:4.6.2'
}

And in my Background library gradle file i have this:

dependencies {
     compile 'com.android.support:support-v4:22.2.0'
}
Max Pinto
  • 1,463
  • 3
  • 16
  • 29

2 Answers2

1

DrawerLayout documentation says the following:

Drawer positioning and layout is controlled using the android:layout_gravity attribute on child views corresponding to which side of the view you want the drawer to emerge from: left or right. (Or start/end on platform versions that support layout direction.)

You must declare either

android:layout_gravity="left|start"

or

android:layout_gravity="right|end"

for the layout that is the sliding drawer viewgroup so the DrawerLayout knows where to position it (where the menu emerges from) and then it can inflate it. With your code as it (without a layout_gravity) the drawer layout will crash since it doesn't know where to put the sliding menu.

Lucas Crawford
  • 3,078
  • 2
  • 14
  • 25
  • well, just adde that line to my listView, however, same error, and well i clean/rebuild/invalidate cache/restart Android Studio. The part i dont understand is that two weeks ago was working nice – Max Pinto Oct 06 '15 at 18:27
  • add your build.gradle file please! – Lucas Crawford Oct 06 '15 at 18:30
  • maybe it has to do with the fact that your are saying compile 'com.android.support:appcompat-v7:+' compile 'com.android.support:support-v4:+' with the '+' sign and your buildToolsVersion isn't correct in matching with the latest version of support/appcompat. It would explain why it doesn't work now but worked last week – Lucas Crawford Oct 06 '15 at 18:30
  • yes, few seconds ago, i try this, and drawerLayout works agains, but another dependencies just stop working such as PagerSlidingTabStrip – Max Pinto Oct 06 '15 at 18:33
  • link the build.gradle – Lucas Crawford Oct 06 '15 at 18:34
0

Finally i found a solution, that i want to share.

I was using my custom Application, but as i was using some libraries that was using android support libraries with diferent versions, so i have to use muldiDexEnabled.

So the solution was to use MultiDexApplication.

So to enable this i have to do this:

app gradle

android {
compileSdkVersion 21
buildToolsVersion "21.1.0"

defaultConfig {
    ...
    minSdkVersion 14
    targetSdkVersion 21
    ...
    // Enabling multidex support.
    multiDexEnabled true
}

}

 dependencies {
    compile 'com.android.support:multidex:1.0.0'
 }

and your android Manifest:

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.example.android.multidex.myapplication">
     <application
      android:name="android.support.multidex.MultiDexApplication">
     </application>
</manifest>

Or if you are already using your custom Application, just be sure to extends to MultiDexApplication

With that you can support multiDex Applications/libraries

More info: MultiDex Android Official Site

Max Pinto
  • 1,463
  • 3
  • 16
  • 29