我创建了2个虚拟设备(一个棒棒糖(api 21))和其他(kitkat(api19))。当我尝试运行我的应用程序时,它在kitkat中加载正常,但出现错误并在api21中关闭。我也尝试过设备,同样的事情发生了。我在这里粘贴了错误日志...有谁知道该怎么办?请帮助!!
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appingapps.narayan.mancalapp/com.appingapps.narayan.mancalapp.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360).....
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)..............
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)....
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 36009012 byte allocation with 524288 free bytes and 31MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method).........
下面的是xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:id="@+id/relativeLayout"
tools:context=".MainActivity">
<ImageButton
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/profileBButton"
android:background="@drawable/profile_pic_ring"
android:scaleType="fitXY"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profileB"
android:textColor="#fffff7f4"
android:layout_alignTop="@+id/profileBButton"
android:layout_toRightOf="@+id/profileBButton"/>
<ImageButton
style="?android:attr/buttonStyleSmall"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@null"
android:layout_marginRight="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:scaleType="fitXY"
android:id="@+id/volume"
android:src="@drawable/yesvolume"
android:onClick="setVolume"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"/>
<ImageButton
style="?android:attr/buttonStyleSmall"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@null"
android:layout_toLeftOf="@+id/volume"
android:layout_alignTop="@+id/volume"
android:scaleType="fitXY"
android:id="@+id/music"
android:src="@drawable/music"
android:onClick="setMusic"/>
<ImageButton
android:layout_width="80dp"
android:layout_height="180dp"
android:id="@+id/blueButton7"
android:clickable="false"
android:background="@null"
android:src="@drawable/kb0"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:layout_centerVertical="true"
android:layout_below="@+id/profileBButton"
android:layout_alignLeft="@+id/profileBButton"/>
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/blueButton6"
android:layout_marginRight="5dp"
android:clickable="false"
android:background="@null"
android:src="@drawable/b0"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:layout_alignTop="@+id/blueButton7"
android:layout_toRightOf="@+id/blueButton7"
android:layout_toEndOf="@+id/blueButton7" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/blueButton5"
android:clickable="false"
android:background="@null"
android:src="@drawable/b0"
android:scaleType="fitXY"
android:onClick="myClickHandlerPlay"
android:layout_marginRight="5dp"
android:layout_alignTop="@+id/blueButton6"
android:layout_toRightOf="@+id/blueButton6"
android:layout_toEndOf="@+id/blueButton6" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/blueButton4"
android:clickable="false"
android:background="@null"
android:src="@drawable/b0"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:layout_marginRight="5dp"
android:layout_alignTop="@+id/blueButton5"
android:layout_toRightOf="@+id/blueButton5"
android:layout_toEndOf="@+id/blueButton5" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/blueButton3"
android:clickable="false"
android:background="@null"
android:src="@drawable/b0"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:layout_marginRight="5dp"
android:layout_alignTop="@+id/blueButton4"
android:layout_toRightOf="@+id/blueButton4"
android:layout_toEndOf="@+id/blueButton4" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/blueButton2"
android:clickable="false"
android:background="@null"
android:src="@drawable/b0"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:layout_marginRight="5dp"
android:layout_alignTop="@+id/blueButton3"
android:layout_toRightOf="@+id/blueButton3"
android:layout_toEndOf="@+id/blueButton3" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/blueButton1"
android:clickable="false"
android:background="@null"
android:src="@drawable/b0"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:layout_marginRight="5dp"
android:layout_alignTop="@+id/blueButton2"
android:layout_toRightOf="@+id/blueButton2"
android:layout_toEndOf="@+id/blueButton2" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/redButton1"
android:clickable="false"
android:background="@null"
android:src="@drawable/r0"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:layout_marginRight="5dp"
android:layout_alignBottom="@+id/blueButton7"
android:layout_toRightOf="@+id/blueButton7"
android:layout_toEndOf="@+id/blueButton7"/>
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/redButton2"
android:clickable="false"
android:onClick="myClickHandlerPlay"
android:background="@null"
android:src="@drawable/r0"
android:scaleType="fitXY"
android:layout_marginRight="5dp"
android:layout_alignTop="@+id/redButton1"
android:layout_toRightOf="@+id/redButton1"
android:layout_toEndOf="@+id/redButton1" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/redButton3"
android:clickable="false"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:background="@null"
android:src="@drawable/r0"
android:layout_marginRight="5dp"
android:layout_alignTop="@+id/redButton2"
android:layout_alignLeft="@+id/blueButton4"
android:layout_alignStart="@+id/blueButton4" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/redButton4"
android:clickable="false"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:background="@null"
android:src="@drawable/r0"
android:layout_marginRight="5dp"
android:layout_alignTop="@+id/redButton3"
android:layout_alignLeft="@+id/blueButton3"
android:layout_alignStart="@+id/blueButton3" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/redButton5"
android:clickable="false"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:layout_marginRight="5dp"
android:background="@null"
android:src="@drawable/r0"
android:layout_alignTop="@+id/redButton4"
android:layout_toRightOf="@+id/redButton4"
android:layout_toEndOf="@+id/redButton4" />
<ImageButton
android:layout_width="55dp"
android:layout_height="75dp"
android:id="@+id/redButton6"
android:clickable="false"
android:onClick="myClickHandlerPlay"
android:scaleType="fitXY"
android:layout_marginRight="5dp"
android:background="@null"
android:src="@drawable/r0"
android:layout_alignTop="@+id/redButton5"
android:layout_toRightOf="@+id/redButton5"
android:layout_toEndOf="@+id/redButton5" />
<ImageButton
android:layout_width="90dp"
android:layout_height="180dp"
android:id="@+id/redButton7"
android:clickable="false"
android:background="@null"
android:src="@drawable/kb0"
android:scaleType="fitXY"
android:layout_alignTop="@+id/blueButton7"
android:layout_alignBottom="@+id/blueButton7"
android:layout_toRightOf="@+id/redButton6"
android:layout_toEndOf="@+id/blueButton1"
android:layout_above="@+id/profileAButton"
android:layout_alignRight="@+id/profileAButton"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lfarrow"
android:src="@drawable/animel"
android:background="@null"
android:scaleType="fitCenter"
android:visibility="invisible"
android:layout_above="@+id/bText1"
android:layout_alignRight="@+id/bText1"
android:layout_alignLeft="@+id/bText5"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/rtarrow"
android:src="@drawable/anime"
android:background="@null"
android:scaleType="fitCenter"
android:visibility="invisible"
android:layout_below="@+id/rText1"
android:layout_alignRight="@+id/rText5"
android:layout_alignLeft="@+id/rText1"/>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/rText1"
android:background="@drawable/score_ring"
android:textStyle="bold"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_below="@+id/redButton1"
android:layout_alignLeft="@+id/redButton1"
android:layout_alignTop="@+id/pause" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/rText2"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_below="@+id/redButton2"
android:layout_alignLeft="@+id/redButton2"
android:textStyle="bold"
android:layout_alignTop="@+id/pause" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/rText3"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_below="@+id/redButton3"
android:layout_alignLeft="@+id/redButton3"
android:textStyle="bold"
android:layout_alignTop="@+id/pause" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/rText4"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_below="@+id/redButton4"
android:layout_alignLeft="@+id/redButton4"
android:textStyle="bold"
android:layout_alignTop="@+id/pause" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/rText5"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_below="@+id/redButton5"
android:layout_alignLeft="@+id/redButton5"
android:textStyle="bold"
android:layout_alignTop="@+id/pause" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/rText6"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_below="@+id/redButton6"
android:layout_alignLeft="@+id/redButton6"
android:textStyle="bold"
android:layout_alignTop="@+id/pause" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/rText7"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_alignBottom="@id/redButton7"
android:layout_alignLeft="@id/redButton7"
android:layout_alignRight="@id/redButton7"
android:textStyle="bold"/>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/bText1"
android:background="@drawable/score_ring"
android:textColor="#fffff7f4"
android:layout_above="@+id/blueButton1"
android:layout_alignLeft="@+id/blueButton1"
android:layout_alignStart="@+id/blueButton1"
android:gravity="center"
android:layout_alignBottom="@+id/profileBButton"
android:textStyle="bold" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/bText2"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_above="@+id/blueButton2"
android:layout_alignLeft="@+id/blueButton2"
android:layout_alignStart="@+id/blueButton2"
android:layout_alignBottom="@+id/profileBButton"
android:textStyle="bold"/>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/bText3"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_above="@+id/blueButton3"
android:layout_alignLeft="@+id/blueButton3"
android:layout_alignStart="@+id/blueButton3"
android:layout_alignBottom="@+id/profileBButton"
android:textStyle="bold"/>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/bText4"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_above="@+id/blueButton4"
android:layout_alignLeft="@+id/blueButton4"
android:layout_alignStart="@+id/blueButton4"
android:layout_alignBottom="@+id/profileBButton"
android:textStyle="bold"/>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/bText5"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_above="@+id/blueButton5"
android:layout_alignLeft="@+id/blueButton5"
android:layout_alignStart="@+id/blueButton5"
android:layout_alignBottom="@+id/profileBButton"
android:textStyle="bold"/>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/bText6"
android:background="@drawable/score_ring"
android:gravity="center"
android:textColor="#fffff7f4"
android:layout_above="@+id/blueButton6"
android:layout_alignLeft="@+id/blueButton6"
android:layout_alignStart="@+id/blueButton6"
android:layout_alignBottom="@+id/profileBButton"
android:textStyle="bold"/>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:text="0"
android:id="@+id/bText7"
android:gravity="center"
android:textColor="#fffff7f4"
android:textStyle="bold"
android:layout_alignTop="@id/blueButton7"
android:layout_alignLeft="@id/blueButton7"
android:layout_alignRight="@id/blueButton7"/>
<ImageButton
style="?android:attr/buttonStyleSmall"
android:layout_width="45dp"
android:layout_height="45dp"
android:text="@string/options"
android:id="@+id/pause"
android:scaleType="fitXY"
android:src="@drawable/homealt"
android:background="@null"
android:onClick="getOptions"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="INFO"
android:id="@+id/info"
android:visibility="gone"
android:textColor="#fffff7f4"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/blueButton1"
android:layout_alignEnd="@+id/blueButton1" />
<ImageButton
android:layout_width="45dp"
android:layout_height="45dp"
android:id="@+id/profileAButton"
android:background="@drawable/profile_pic_ring"
android:layout_alignParentRight="true"
android:scaleType="fitXY"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/pause" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profileA"
android:textColor="#fffff7f4"
android:layout_alignBottom="@+id/profileAButton"
android:layout_toLeftOf="@id/profileAButton"/>
答案 0 :(得分:1)
我的猜测是你有一个大图像(或更多),它位于较低密度屏幕的可绘制文件夹之一(如drawable
)所以当你在高密度屏幕上运行你的应用程序时,android upcales你已经很大的图像到一个巨大的分辨率,并试图为它分配大量的内存。如果是这种情况,您只需将图像移动到更合适的文件夹,例如drawable-xxhdpi
。