Android RuntimeException:添加几个ImageButton后无法启动activity ComponentInfo

Android RuntimeException:添加几个ImageButton后无法启动activity ComponentInfo,android,android-studio,Android,Android Studio,我的应用程序工作没有问题,直到我添加了几个ImageButton(其中一个没有问题) 和XML <RelativeLayout 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" andr

我的应用程序工作没有问题,直到我添加了几个ImageButton(其中一个没有问题)

和XML

<RelativeLayout 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:background="#6c6976"
tools:context=".ChooseMapActivity">

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="left|center_vertical">

        <Button
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:id="@+id/dust2_button"
            android:background="@drawable/dust2_custom_button"
            android:layout_marginTop="15dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <Button
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:id="@+id/cache_button"
            android:layout_alignTop="@+id/dust2_button"
            android:layout_toRightOf="@+id/dust2_button"
            android:layout_toEndOf="@+id/dust2_button"
            android:background="@drawable/cache_custom_button"/>

        <Button
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:id="@+id/nuke_button"
            android:layout_below="@+id/dust2_button"
            android:layout_alignLeft="@+id/dust2_button"
            android:layout_alignStart="@+id/dust2_button"
            android:background="@drawable/nuke_custom_button"/>

        <Button
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:id="@+id/mirage_button"
            android:layout_below="@+id/nuke_button"
            android:layout_alignLeft="@+id/nuke_button"
            android:layout_alignStart="@+id/nuke_button"
            android:background="@drawable/mirage_custom_button"/>

    <Button
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:id="@+id/overpass_button"
        android:layout_above="@+id/mirage_button"
        android:layout_toRightOf="@+id/nuke_button"
        android:layout_toEndOf="@+id/nuke_button"
        android:background="@drawable/overpass_custom_button"/>

    <Button
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:id="@+id/inferno_button"
        android:layout_below="@+id/nuke_button"
        android:layout_toRightOf="@+id/nuke_button"
        android:layout_toEndOf="@+id/nuke_button"
        android:background="@drawable/inferno_custom_button"/>

    <Button
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:id="@+id/cobblestone_button"
        android:layout_below="@+id/mirage_button"
        android:layout_alignLeft="@+id/mirage_button"
        android:layout_alignStart="@+id/mirage_button"
        android:background="@drawable/cobblestone_custom_button"/>

    <Button
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:id="@+id/train_button"
        android:layout_alignTop="@+id/cobblestone_button"
        android:layout_toRightOf="@+id/cobblestone_button"
        android:layout_toEndOf="@+id/cobblestone_button"
        android:background="@drawable/train_custom_button"/>

    </RelativeLayout>

android:layout\u width=“匹配父项”
android:layout\u height=“match\u parent”
android:layout_gravity=“left | center_vertical”>

我试图找到解决方案,但对我来说,ChooseSpactivity类中的第18行完全没问题,有什么想法吗?

您的XML无效,您的第一个标记关闭了两次。删除此部分:

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="left|center_vertical">

这将出现在您的日志中:

 Caused by: java.lang.OutOfMemoryError: Failed to allocate a 4000012 byte allocation with 1511784 free bytes and 1476KB until OOM

这可能是因为位图较大,可能是图像较小。

您得到的
OutOfMemoryError
可能是因为位图较大,可能是图像较小,修复了一个问题,谢谢!你好@henorek,我发布了我的答案,所以你可以标记为接受。
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="left|center_vertical">
 Caused by: java.lang.OutOfMemoryError: Failed to allocate a 4000012 byte allocation with 1511784 free bytes and 1476KB until OOM