简体   繁体   English

java.lang.ClassCastException:android.widget.RelativeLayout $ LayoutParams无法转换为android.support.v4.widget.DrawerLayout $ LayoutParams

[英]java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams

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: 这是我的activity_main布局:

<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): 这是我单击列表项时调用的activity_entidade布局(这实际上是一个片段):

<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>

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 在这里查看我的答案: ClassCastException:java.lang.ClassCastException:android.widget.LinearLayout $ LayoutParams无法转换为android.support.v4.widget.DrawerLayout

Just use your DrawerLayout to close himself or use closeDrawers() on your DrawerLayout object; 只需使用DrawerLayout关闭自己或在DrawerLayout对象上使用closeDrawers() DrawerLayout

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassCastException:android.widget.RelativeLayout $ LayoutParams无法强制转换为android.support.v7.widget.RecyclerView $ LayoutParams - java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams ClassCastException:java.lang.ClassCastException:android.widget.LinearLayout $ LayoutParams无法强制转换为android.support.v4.widget.DrawerLayout - ClassCastException : java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout java.lang.ClassCastException:android.widget.RelativeLayout $ LayoutParams无法转换为android.widget.LinearLayout $ LayoutParams - java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams java.lang.ClassCastException:android.widget.RelativeLayout $ LayoutParams无法转换为android.widget.FrameLayout $ LayoutParams - java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams java.lang.ClassCastException:android.view.ViewGroup$LayoutParams 不能转换为 android.widget.RelativeLayout$LayoutParams - java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams 获取java.lang.ClassCastException:android.widget.FrameLayout $ LayoutParams无法强制转换为android.widget.RelativeLayout $ LayoutParams - Getting java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams 无法将RelativeLayout $ LayoutParams强制转换为android.support.v4.widget.DrawerLayout $ LayoutParams - RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams ClassCastException:无法将android.widget.RelativeLayout $ LayoutParams强制转换为Activity内部的android.support.v7.widget.RecyclerView $ LayoutParams - ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams inside activity java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 不能转换为 android.support.v7.widget.RecyclerView$LayoutParams - java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams 无法将widget.FrameLayout $ LayoutParams强制转换为android.support.v4.widget.DrawerLayout $ LayoutParams - widget.FrameLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM