Przyczyna: java.lang.OutOfMemoryError: rozmiar bitmapy przekracza budżet VM
W mojej aplikacji, gdy próbuję ją uruchomić, Force Closed i błąd wskazujący linię „setContentView (R.layout.Menu);” układu. W pliku XML pokazuje widok obrazu „OutOfMemoryError” w moim układzie. Naprawdę jestem zdezorientowany. Proszę, poprowadź mnie do dalszych ruchów.
Edytowane:
Moja aplikacja korzysta z bazy danych i po raz pierwszy analizuje niektóre dane XML i wstawia je do bazy danych Sqlite. Mój problem pamięci zewnętrznej występuje tylko za pierwszym razem. Drugi raz działa dobrze. Próbowałem System.gc (). Czy jest w tym jakiś problem?
To jest mój dziennik:
<code>E/dalvikvm-heap(2712): 105376-byte external allocation too large for this process. VM won't let us allocate 105376 bytes FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Test/com.Test.Menu}: android.view.InflateException: Binary XML file line #13: Error inflating class <unknown> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) at android.app.ActivityThread.access$1500(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3683) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class <unknown> at android.view.LayoutInflater.createView(LayoutInflater.java:518) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568) at android.view.LayoutInflater.rInflate(LayoutInflater.java:623) at android.view.LayoutInflater.rInflate(LayoutInflater.java:626) at android.view.LayoutInflater.inflate(LayoutInflater.java:408) at android.view.LayoutInflater.inflate(LayoutInflater.java:320) at android.view.LayoutInflater.inflate(LayoutInflater.java:276) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207) at android.app.Activity.setContentView(Activity.java:1657) at com.Test.Menu.onCreate(Menu.java:32) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) ... 11 more Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:415) at android.view.LayoutInflater.createView(LayoutInflater.java:505) ... 23 more Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697) at android.content.res.Resources.loadDrawable(Resources.java:1709) at android.content.res.TypedArray.getDrawable(TypedArray.java:601) at android.widget.ImageView.<init>(ImageView.java:118) at android.widget.ImageView.<init>(ImageView.java:108) </code>
To jest mój kod XML:
<code><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <RelativeLayout android:id="@+id/RL_Title" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="8" android:onClick="onTitleClick" > <ImageView android:id="@+id/Img_Title_bg" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="center" android:src="@drawable/title_bg" /> <Button android:id="@+id/Btn_Title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginRight="5dp" android:background="@drawable/title_al" android:drawableRight="@drawable/pro" android:gravity="center" android:onClick="onTitleClick" /> </RelativeLayout> <RelativeLayout android:id="@+id/RL_MainMenu" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:onClick="onDoNothing"> <ImageView android:id="@+id/ImageView01" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="4" android:src="@drawable/main_bg" android:scaleType="centerCrop"/> <ImageView android:id="@+id/Img_logo" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="4" android:scaleType="center" android:src="@drawable/logo_al" /> <LinearLayout android:id="@+id/LI_Menu" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/RL_ExtraOption" android:layout_alignTop="@+id/Img_logo" android:layout_margin="2dp" android:orientation="vertical" > <ImageButton android:id="@+id/Img_Buyer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@drawable/bt_blink" android:onClick="Nextclick" android:scaleType="fitCenter" android:soundEffectsEnabled="true" android:src="@drawable/buyer_icon" /> <ImageButton android:id="@+id/Img_Seller" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@drawable/bt_blink" android:onClick="Nextclick" android:scaleType="fitCenter" android:src="@drawable/seller_icon" /> <ImageButton android:id="@+id/Img_Lender" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@drawable/bt_blink" android:onClick="Nextclick" android:scaleType="fitCenter" android:src="@drawable/lender_icon" /> <ImageButton android:id="@+id/Img_myTitleRep" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@drawable/bt_blink" android:onClick="Nextclick" android:scaleType="fitCenter" android:src="@drawable/my_title_rep_icon_al" /> <ImageButton android:id="@+id/Img_Setup" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="1dp" android:layout_weight="1" android:background="@drawable/bt_blink" android:onClick="Nextclick" android:scaleType="fitCenter" android:src="@drawable/setup_icon" /> </LinearLayout> <RelativeLayout android:id="@+id/RL_ExtraOption" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@drawable/main_bottom_bg" > <TextView android:id="@+id/txt_RepName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:textColor="@color/white" android:textSize="@dimen/font_size" /> <TableRow android:id="@+id/TR_ContactRep" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:gravity="center" > <Button android:id="@+id/Btn_ContactRep" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="3dp" android:background="@drawable/contact_rep_blink" android:onClick="ContactRep_Click" /> <Button android:id="@+id/Btn_MoreOption" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="5dp" android:background="@drawable/main_more_blink" android:onClick="onMoreClick" /> </TableRow> </RelativeLayout> <LinearLayout android:id="@+id/ln_Mainmore" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/dialog_bg" android:layout_alignParentBottom="true" android:visibility="gone"> <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="3" android:orientation="vertical" > </LinearLayout> <TableLayout android:id="@+id/TableLayout01" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" > <TableRow android:id="@+id/TableRow04" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:layout_marginTop="20dp" android:gravity="center" > <Button android:id="@+id/Btn_Rate" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/property_blue_blink" android:onClick="onRate" android:singleLine="true" android:text="Rate/Testimonial" android:textColor="@color/white" android:textSize="@dimen/font_size" android:textStyle="bold" /> </TableRow> <TableRow android:id="@+id/TableRow01" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:gravity="center" > <Button android:id="@+id/btn_SubFeature" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/property_blue_blink" android:onClick="onSubFeature" android:singleLine="true" android:text="Submit A Feature" android:textColor="@color/white" android:textSize="@dimen/font_size" android:textStyle="bold" /> </TableRow> <TableRow android:id="@+id/TableRow03" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:gravity="center" > <Button android:id="@+id/Btn_ReferFrnd" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/property_blue_blink" android:onClick="onReferAFrnd" android:text="Refer A Friend" android:textColor="@color/white" android:textSize="@dimen/font_size" android:textStyle="bold" /> </TableRow> <TableRow android:id="@+id/TableRow02" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" android:gravity="center" > <Button android:id="@+id/Btn_cancel" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/property_cancel_blink" android:onClick="onClose" android:text="Cancel" android:textColor="@color/black" android:textSize="@dimen/font_size" android:textStyle="bold" /> </TableRow> </TableLayout> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="3" android:orientation="vertical" > </LinearLayout> </LinearLayout> </RelativeLayout> </code>