0

I have an app and I'm getting this error message. When I run, it runs fine, but when I select an item o the navigation drawer I get the exception. Here's my Error Log:

 Process: com.example.henrique.testedrawer2, PID: 26739
    java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
            at android.support.v4.widget.DrawerLayout.isDrawerView(DrawerLayout.java:1100)
            at android.support.v4.widget.DrawerLayout.closeDrawer(DrawerLayout.java:1305)
            at com.example.henrique.testedrawerKiron.MainActivity.selectItem(MainActivity.java:133)
            at com.example.henrique.testedrawerKiron.MainActivity.access$100(MainActivity.java:26)
            at com.example.henrique.testedrawerKiron.MainActivity$DrawerItemClickListener.onItemClick(MainActivity.java:96)
            at android.widget.AdapterView.performItemClick(AdapterView.java:305)
            at android.widget.AbsListView.performItemClick(AbsListView.java:1146)
            at android.widget.AbsListView$PerformClick.run(AbsListView.java:3053)
            at android.widget.AbsListView$3.run(AbsListView.java:3860)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Here's my activity_main layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <include layout="@layout/toolbar" />


    <android.support.v4.widget.DrawerLayout
        android:layout_width="match_parent"
        android:id="@+id/drawerLayout"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="Teste"/>

        <!-- navigation drawer -->
        <RelativeLayout
            android:layout_gravity="left|start"
            android:layout_width="match_parent"
            android:background="#fff"
            android:layout_height="match_parent">

            <ListView
                android:id="@+id/left_drawer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="#eee"
                android:background="#fff"
                android:dividerHeight="1dp" />
        </RelativeLayout>

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

</LinearLayout>

Here's my activity_entidade layout that it's called when I click a list item(this is acctually a fragment):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.henrique.testedrawerKiron.EntidadeActivity">

   <ListView
       android:id="@+id/listaentidades"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       />

</LinearLayout>
2
  • you need to post the Code where you are playing around the LayoutParameters. Commented May 13, 2015 at 18:59
  • Check your imports and where you instanciate that drawerlayout. your casting a relative layout into a drawerlayout somewhere in your activity Commented May 13, 2015 at 19:00

1 Answer 1

1

I think you are closing wrong layout in your code.

Look here at my answer: ClassCastException : java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout

Just use your DrawerLayout to close himself or use closeDrawers() on your DrawerLayout object;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.