I have written a small Android project that shows some (image)buttons. It works fine on my phone ( Galaxy S ), but when I try to run it on emulator, it gives the following error:
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
Please note, first activity, has 8 image buttons, and it gives out of memory exception. When I remove 3 buttons, it works fine. Actually, it works fine as long as scrollView is inivisble and If I add those 3 removed buttons ( so, scrollView is going to be visible ), it gives out of memory error. I think, this “out of memory” exception is not related to the number of (image) buttons, but is related to background image. Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="@drawable/backgrounmobile" />
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left|top|bottom|right" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/centerlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right|top|bottom"
android:layout_marginBottom="10dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="20dip"
android:layout_marginTop="0dip"
android:orientation="vertical" >
<Button
android:id="@+id/divan"
android:layout_width="160dip"
android:layout_height="110dip"
android:layout_gravity="center|top"
android:background="@drawable/divanbtn" />
<Button
android:id="@+id/boostan"
android:layout_width="160dip"
android:layout_height="110dip"
android:layout_gravity="center|top"
android:background="@drawable/boostanbtn" />
<Button
android:id="@+id/mavaez"
android:layout_width="160dip"
android:layout_height="110dip"
android:layout_gravity="center|top"
android:background="@drawable/mavaezbtn" />
<Button
android:id="@+id/hekayat"
android:layout_width="160dip"
android:layout_height="110dip"
android:layout_gravity="center|top"
android:background="@drawable/hekayatbtn" />
<Button
android:id="@+id/saadiname"
android:layout_width="160dip"
android:layout_height="110dip"
android:layout_gravity="center|top"
android:background="@drawable/saadinamebtn" />
<Button
android:id="@+id/settings"
android:layout_width="160dip"
android:layout_height="110dip"
android:layout_gravity="center|top"
android:background="@drawable/settingsbtn" />
<Button
android:id="@+id/about"
android:layout_width="160dip"
android:layout_height="110dip"
android:layout_gravity="center|top"
android:background="@drawable/aboutbtn" />
</LinearLayout>
</ScrollView>
</FrameLayout>
</LinearLayout>
Would you please help me?
Your running low on memory, and the best way to remedy that will be to use less memory, loading smaller images will help a great deal here, and googles android team have been kind enough to put up a short description on how to do this 🙂
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html