Android studio 当<;出现未处理的异常时,应用程序退出;相对寿命>;包含<;android.support.v4.widget.DrawerLayout/>;

Android studio 当<;出现未处理的异常时,应用程序退出;相对寿命>;包含<;android.support.v4.widget.DrawerLayout/>;,android-studio,Android Studio,每当我在RelativeLayout中有抽屉布局时,我的应用程序就会崩溃。我在网上搜寻类似的东西,但什么也没看到。项目在预览中正确渲染,但在emulator上运行时会崩溃。以下是我的XML: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_

每当我在RelativeLayout中有抽屉布局时,我的应用程序就会崩溃。我在网上搜寻类似的东西,但什么也没看到。项目在预览中正确渲染,但在emulator上运行时会崩溃。以下是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black">

    <ImageView
        android:id="@+id/bnrLogoYellow"
        android:layout_width="195dp"
        android:layout_height="69dp"
        android:layout_centerHorizontal="true"
        android:src="@drawable/bnrlogo_yellow" />

    <ImageButton
        android:id="@+id/imgbtnGrub"
        android:layout_width="95dp"
        android:layout_height="95dp"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@android:color/black"
        android:scaleType="fitXY"
        android:src="@drawable/burgersquare"
        android:layout_below="@+id/bnrLogoYellow"/>

    <ImageButton
        android:id="@+id/imgbtnPub"
        android:layout_width="95dp"
        android:layout_height="95dp"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@android:color/black"
        android:scaleType="fitXY"
        android:src="@drawable/pubsquare1"
        android:layout_below="@+id/bnrLogoYellow"
        android:layout_toRightOf="@+id/imgbtnGrub"/>

    <ImageButton
        android:id="@+id/imgbtnKooz"
        android:layout_width="95dp"
        android:layout_height="95dp"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@android:color/black"
        android:scaleType="fitXY"
        android:src="@drawable/koozsquare"
        android:layout_below="@+id/bnrLogoYellow"
        android:layout_toRightOf="@+id/imgbtnPub"/>

    <ImageButton
        android:id="@+id/imgbtnMore"
        android:layout_width="95dp"
        android:layout_height="95dp"
        android:layout_weight="1"
        android:adjustViewBounds="true"
        android:background="@android:color/black"
        android:scaleType="fitXY"
        android:src="@drawable/moresquare"
        android:layout_below="@+id/bnrLogoYellow"
        android:layout_toRightOf="@+id/imgbtnKooz"/>

    <ImageView
        android:id="@+id/DemoImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@null"
        android:scaleType="fitXY"
        android:layout_below="@+id/imgbtnGrub"
        android:layout_alignParentBottom = "true"
        android:src="@drawable/slidemenu1" />

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="150dp"
        android:layout_height="250dp"
        android:layout_below="@+id/imgbtnGrub"
        android:layout_alignParentBottom = "true">

        <ListView
            android:id="@+id/navList"
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:layout_gravity="left|start"
            android:alpha="0.75"
            android:background="#ffee33"
            android:divider="@null"
            android:theme="?attr/textAppearanceListItemSmall" />

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

</RelativeLayout>

我甚至不用编写任何Java代码就可以复制异常。我得到的例外是:

java.lang.NoClassDefFoundError:使用启动类找不到类 装载机;没有可用的堆栈跟踪

android.widget.ViewStub


非常感谢您的帮助

虽然不是真正的解决方案,但我确实找到了解决办法。我将抽屉布局包裹在一个线性布局内,该线性布局位于相对物框架内。下面是我的XML的最终外观:

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout"
        android:layout_below="@id/imgbtnGrub"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="150dp"
        android:layout_height="250dp"
        android:layout_below="@+id/imgbtnGrub"
        android:layout_alignParentBottom = "true">


        <ListView
            android:id="@+id/navList"
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:layout_gravity="left|start"
            android:alpha="0.75"
            android:background="#ffee33"
            android:divider="@null"
            android:theme="?attr/textAppearanceListItemSmall" />

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


希望它能帮助其他可能遇到相同问题的人。

这可能是一个愚蠢的问题,但您尝试过不同的布局吗?我希望可以使用其他布局方案,但我真的需要使用相对的布局。另一方面,我创建了一个测试项目,并将DroperLayout包装在一个LinearLayout中,当我运行它时,它并没有崩溃——所以它肯定是DroperLayout不喜欢的RelativeLayout。