0

我有一个处理图像的应用程序,它适用于某些设备前。HTC ONE X 和其他人没有。GALAXY NOTE,这个列表很大 IDK 这个问题完全是因为它在某些方面有效,而在其他方面则无效。它也不适用于模拟器默认的一个,但它确实可以工作的一个小模拟器

这是我得到的 logcat

08-15 18:30:39.070: I/dalvikvm-heap(334): Clamp target GC heap from 25.723MB to 24.000MB
08-15 18:30:39.090: D/dalvikvm(334): GC_FOR_MALLOC freed <1K, 51% free 2672K/5379K, external 19015K/19657K, paused 38ms
08-15 18:30:39.370: D/dalvikvm(334): GC_EXTERNAL_ALLOC freed <1K, 51% free 2672K/5379K, external 19015K/19657K, paused 45ms
08-15 18:30:39.400: E/dalvikvm-heap(334): 810000-byte external allocation too large for this process.
08-15 18:30:39.510: I/dalvikvm-heap(334): Clamp target GC heap from 25.724MB to 24.000MB
08-15 18:30:39.510: E/GraphicsJNI(334): VM won't let us allocate 810000 bytes
08-15 18:30:39.510: D/dalvikvm(334): GC_FOR_MALLOC freed 0K, 51% free 2672K/5379K, external 19015K/19657K, paused 36ms
08-15 18:30:39.532: D/AndroidRuntime(334): Shutting down VM
08-15 18:30:39.532: W/dalvikvm(334): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-15 18:30:39.600: E/AndroidRuntime(334): FATAL EXCEPTION: main
08-15 18:30:39.600: E/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.com.android.editor/app.com.android.editor.Option}: android.view.InflateException: Binary XML file line #317: Error inflating class <unknown>
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.os.Looper.loop(Looper.java:123)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.app.ActivityThread.main(ActivityThread.java:3683)
08-15 18:30:39.600: E/AndroidRuntime(334):  at java.lang.reflect.Method.invokeNative(Native Method)
08-15 18:30:39.600: E/AndroidRuntime(334):  at java.lang.reflect.Method.invoke(Method.java:507)
08-15 18:30:39.600: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-15 18:30:39.600: E/AndroidRuntime(334):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-15 18:30:39.600: E/AndroidRuntime(334):  at dalvik.system.NativeStart.main(Native Method)
08-15 18:30:39.600: E/AndroidRuntime(334): Caused by: android.view.InflateException: Binary XML file line #317: Error inflating class <unknown>
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
08-15 18:30:39.600: E/AndroidRuntime(334):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-15 18:30:39.600: E/AndroidRuntime(334):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.app.Activity.setContentView(Activity.java:1657)
08-15 18:30:39.600: E/AndroidRuntime(334):  at app.com.android.editor.Option.onCreate(Option.java:40)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-15 18:30:39.600: E/AndroidRuntime(334):  ... 11 more
08-15 18:30:39.600: E/AndroidRuntime(334): Caused by: java.lang.reflect.InvocationTargetException
08-15 18:30:39.600: E/AndroidRuntime(334):  at java.lang.reflect.Constructor.constructNative(Native Method)
08-15 18:30:39.600: E/AndroidRuntime(334):  at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.LayoutInflater.createView(LayoutInflater.java:505)
08-15 18:30:39.600: E/AndroidRuntime(334):  ... 25 more
08-15 18:30:39.600: E/AndroidRuntime(334): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.graphics.Bitmap.nativeCreate(Native Method)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.content.res.Resources.loadDrawable(Resources.java:1709)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.view.View.<init>(View.java:1951)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.widget.TextView.<init>(TextView.java:344)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.widget.Button.<init>(Button.java:108)
08-15 18:30:39.600: E/AndroidRuntime(334):  at android.widget.Button.<init>(Button.java:104)
08-15 18:30:39.600: E/AndroidRuntime(334):  ... 28 more
08-15 18:30:45.459: I/Process(334): Sending signal. PID: 334 SIG: 9
4

4 回答 4

4

堆大小因设备而异。在应用程序具有大堆大小的设备上,与应用程序具有较小堆大小的设备相比,您遇到的问题更少,这是完全合理的。如果您支持较旧/较低分辨率的设备,您的堆可能低至 16MB。

于 2012-08-15T15:38:46.473 回答
2

大多数android的空间有限。通常为 16MB。我强烈建议查看您的图像大小。尽可能使用弱引用来确保图像仅在访问时使用内存。(弱引用将迫使收集的垃圾更快地清理它们。)

  • 而且我对您的应用程序了解不多,只是您的 logcat 错误列表,但是如果您有多个活动,请杀死不需要的活动。似乎是显而易见的建议,也许不是,但它会释放空间。
于 2012-08-15T15:39:08.667 回答
2

正如其他人所说,应用程序的堆大小是有限的。最小值为 16MB,并且因设备而异(这是虚拟机的设置)。

一些建议你可以做什么:

  1. 如果不需要全分辨率,您可以加载较小版本的图像。这是如何做到的:http: //developer.android.com/reference/android/graphics/BitmapFactory.Options.html
  2. 检查是否有足够的空闲内存可用;如果内存不足,您可以立即释放不直接需要的图像,并在需要时再次加载它们。

以下是一些用于检查剩余可用内存量的代码:

long free = Runtime.getRuntime().freeMemory();
于 2012-08-15T15:59:12.193 回答
1
 Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

那条线说明了一切。位图占用了某些设备(VM 堆栈限制较高的设备)的所有内存。您应该为这个应用程序寻找更好的内存管理,例如 LruCache、解码质量较低的位图等。

编辑: 不要像某些用户建议的那样使用 Wea​​kReference。检查这个问题Android是否需要在采样之前从文件中加载完整的位图?还有这个视频http://www.youtube.com/watch?v=gbQb1PVjfqM

来自平台创建者的直接解释/教学/技术,并说不要使用 Wea​​kReference。

于 2012-08-15T15:39:22.100 回答