2013-12-21 275 views
0

這個應用程序工作正常,沒有更少的圖像,具體更小的圖像大小。但我需要使用大量的圖像,並無法安裝在手機內存我試着安裝應用程序在我的SD卡上,並得到了這個錯誤。 不明白爲什麼。 如何解決這個應用程序在啓動後崩潰

這是日誌貓說

E/dalvikvm-heap(17405): Out of memory on a 3234424-byte allocation. 
E/AndroidRuntime(17405): FATAL EXCEPTION: main 
E/AndroidRuntime(17405): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mystictreegames.pagecurl/com.mystictreegames.pagecurl.StandaloneExample}: android.view.InflateException: Binary XML file line #6: Error inflating class com.mystictreegames.pagecurl.PageCurlView 
E/AndroidRuntime(17405): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343) 
E/AndroidRuntime(17405): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 
E/AndroidRuntime(17405): at android.app.ActivityThread.access$600(ActivityThread.java:162) 
E/AndroidRuntime(17405): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364) 
E/AndroidRuntime(17405): at android.os.Handler.dispatchMessage(Handler.java:107) 
E/AndroidRuntime(17405): at android.os.Looper.loop(Looper.java:194) 
E/AndroidRuntime(17405): at android.app.ActivityThread.main(ActivityThread.java:5371) 
E/AndroidRuntime(17405): at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime(17405): at java.lang.reflect.Method.invoke(Method.java:525) 
E/AndroidRuntime(17405): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) 
E/AndroidRuntime(17405): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 
E/AndroidRuntime(17405): at dalvik.system.NativeStart.main(Native Method) 
E/AndroidRuntime(17405): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.mystictreegames.pagecurl.PageCurlView 
E/AndroidRuntime(17405): at android.view.LayoutInflater.createView(LayoutInflater.java:613) 

和我的存儲卡幾乎是空的。

這是standalone_example.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <com.mystictreegames.pagecurl.PageCurlView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/dcgpagecurlPageCurlView1" 
     android:background="@drawable/background"> 
    </com.mystictreegames.pagecurl.PageCurlView> 
</LinearLayout> 

和我main.xml中只含有一個ImageButton的 我應該張貼也?

+2

你可以發佈你的XML文件有一個錯誤的XML文件.. –

+0

張貼您的XML文件,那裏有問題 – Rudi

+0

XML中沒有錯誤。它引用的圖像太大了。圖像大小是多少? – Simon

回答

0

確保PageCurlView被放置在com.mystictreegames.pagecurl

-1

必須使用bitmap.recycle回收位圖()。如果你沒有回收你的位圖,你可能會遇到內存不足的例外。

所以使用

bitmap.recycle(); 
bitmap = null; 

這將確保該位是垃圾收集。

否則,如果這是內存問題,那麼您可以使用

android:largeHeap="true" 

您的清單應用程序標籤內。這將允許你加載更多的位圖...希望這會幫助你。快樂編碼...

+0

由於OP沒有在代碼中加載圖像,所以這是無關緊要的,沒有大量的大堆可以讓您在該分辨率下加載35個圖像。 – Simon