2

程序加载正常,我可以通过几个屏幕,但是当 main.xml 尝试加载时,程序仅在 api 14 上崩溃。

日志输出:

04-26 09:02:14.290: E/AndroidRuntime(566): FATAL EXCEPTION: main
04-26 09:02:14.290: E/AndroidRuntime(566): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.surreall.yacht/com.surreall.yacht.yatzee}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.os.Looper.loop(Looper.java:137)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.main(ActivityThread.java:4340)
04-26 09:02:14.290: E/AndroidRuntime(566):  at java.lang.reflect.Method.invokeNative(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566):  at java.lang.reflect.Method.invoke(Method.java:511)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-26 09:02:14.290: E/AndroidRuntime(566):  at dalvik.system.NativeStart.main(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.Activity.setContentView(Activity.java:1835)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.surreall.yacht.yatzee.onCreate(yatzee.java:211)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.Activity.performCreate(Activity.java:4465)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
04-26 09:02:14.290: E/AndroidRuntime(566):  ... 11 more
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: java.lang.reflect.InvocationTargetException
04-26 09:02:14.290: E/AndroidRuntime(566):  at java.lang.reflect.Constructor.constructNative(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.createView(LayoutInflater.java:586)
04-26 09:02:14.290: E/AndroidRuntime(566):  ... 23 more
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: java.lang.OutOfMemoryError
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.Bitmap.nativeCreate(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.content.res.Resources.loadDrawable(Resources.java:1937)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.View.<init>(View.java:2780)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.ViewGroup.<init>(ViewGroup.java:385)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.widget.LinearLayout.<init>(LinearLayout.java:174)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.widget.LinearLayout.<init>(LinearLayout.java:170)
04-26 09:02:14.290: E/AndroidRuntime(566):  ... 26 more

由于堆栈溢出的 30k 个字符问题限制,我无法发布 main.xml 的内容,而且还不止这些。从哪里开始的建议?

4

4 回答 4

2

在这里发现了类似的问题

显然这是 android 模拟器的堆大小问题。我将用于 API 14 的模拟器的 AVD 中的“最大 VM 应用程序堆大小”从 24 更改为 48,并且它不再崩溃。它仍然不能完全解释为什么 API 从使用 6mb 的堆变为 23.5mb,我希望最终用户设备上的硬件都至少有 48mb 的堆,否则他们的应用程序会崩溃。现在我将其标记为已修复。

于 2012-05-02T00:28:35.940 回答
1

according to my experience , it can also occur on a real device - the exact same out-of-memory exception occured for me on the galaxy nexus . i think it occurs because of the resolution .

here are possible solutions:

  1. sample the images according to your need.
  2. set a larger heap size in the manifest.
  3. if the images are static , create your own imageView alternative , which only shows the image and after that doesn't hold a reference to it (or use softreference and a builder instead) .
  4. use opengl /ndk or whatever framework that can bypass the heap size limit .
  5. in any case , do not store all of your images . instead , store only those that you need currently , and the rest can stay in your cache (which could be LRU cache or softreference cache ) .
于 2012-05-04T08:41:24.413 回答
1

您尝试在布局中加载太大的图像。请参阅错误消息的底部:

OutOfMemoryError
Resources.loadDrawable()

它在一个里面的某个地方LinearLayout

于 2012-04-28T23:58:40.783 回答
0

检查问题是否与自 API 14 以来默认启用的硬件加速无关,更多信息在这里:

http://developer.android.com/guide/topics/graphics/hardware-accel.html

在我正在处理的一个应用程序中,我们在一个特定视图上崩溃了,这是由 API 14 启用的硬件加速引起的。上面的链接显示了如何在多个级别禁用它,在我的例子中,只是在视图级别禁用它,因为如果您尝试使用新主题(自 ICS 以来引入),禁用整个应用程序会导致一些问题。

于 2013-08-23T20:55:40.210 回答