0

我知道关于这个话题有很多问题和答案,但是我有一个非常奇怪的行为,我在这个非常奇怪的错误的许多解释中都找不到。

当我将屏幕传递从一个活动旋转到另一个活动并发生在新创建的活动中时,该错误随机发生在我的应用程序中:

layout.setBackgroundResource(R.drawable.background);

我尝试过使用漂亮、厚重的 jpeg 背景和柔和、浅色的单色背景,但结果是一样的。

我试图用一个按钮制作一个简单的应用程序来在两个活动之间切换,但我无法重现该错误。

我试图在受罪行之前设置一个断点,并且没有问题,就像等待使应用程序正常工作一样。

我从不使用加载位图的方法,我不知道发生了什么。

感谢您的帮助,如果您认为我可以添加一些有用的信息,请告诉我,我添加了我所做的一切,我希望这已经足够了。

这是 logCat 输出:

10-01 16:31:16.750: E/ACRA(12765): com.controller fatal error : Unable to start activity ComponentInfo{com.controller/pages.RicercaAllarmiPage}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
10-01 16:31:16.750: E/ACRA(12765): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.controller/pages.RicercaAllarmiPage}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
10-01 16:31:16.750: E/ACRA(12765):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
10-01 16:31:16.750: E/ACRA(12765):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
10-01 16:31:16.750: E/ACRA(12765):  at android.app.ActivityThread.access$1500(ActivityThread.java:121)
10-01 16:31:16.750: E/ACRA(12765):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
10-01 16:31:16.750: E/ACRA(12765):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-01 16:31:16.750: E/ACRA(12765):  at android.os.Looper.loop(Looper.java:130)
10-01 16:31:16.750: E/ACRA(12765):  at android.app.ActivityThread.main(ActivityThread.java:3770)
10-01 16:31:16.750: E/ACRA(12765):  at java.lang.reflect.Method.invokeNative(Native Method)
10-01 16:31:16.750: E/ACRA(12765):  at java.lang.reflect.Method.invoke(Method.java:507)
10-01 16:31:16.750: E/ACRA(12765):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
10-01 16:31:16.750: E/ACRA(12765):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
10-01 16:31:16.750: E/ACRA(12765):  at dalvik.system.NativeStart.main(Native Method)
10-01 16:31:16.750: E/ACRA(12765): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
10-01 16:31:16.750: E/ACRA(12765):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
10-01 16:31:16.750: E/ACRA(12765):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-01 16:31:16.750: E/ACRA(12765):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
10-01 16:31:16.750: E/ACRA(12765):  at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
10-01 16:31:16.750: E/ACRA(12765):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-01 16:31:16.750: E/ACRA(12765):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-01 16:31:16.750: E/ACRA(12765):  at pages.RicercaAllarmiPage.drawRicercaAllarmi(RicercaAllarmiPage.java:112)
10-01 16:31:16.750: E/ACRA(12765):  at pages.RicercaAllarmiPage.onCreate(RicercaAllarmiPage.java:94)
10-01 16:31:16.750: E/ACRA(12765):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
10-01 16:31:16.750: E/ACRA(12765):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
10-01 16:31:16.750: E/ACRA(12765):  ... 11 more
10-01 16:31:16.750: E/ACRA(12765): Caused by: java.lang.reflect.InvocationTargetException
10-01 16:31:16.750: E/ACRA(12765):  at java.lang.reflect.Constructor.constructNative(Native Method)
10-01 16:31:16.750: E/ACRA(12765):  at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
10-01 16:31:16.750: E/ACRA(12765):  at android.view.LayoutInflater.createView(LayoutInflater.java:505)
10-01 16:31:16.750: E/ACRA(12765):  ... 20 more
10-01 16:31:16.750: E/ACRA(12765): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
10-01 16:31:16.750: E/ACRA(12765):  at android.graphics.Bitmap.nativeCreate(Native Method)
10-01 16:31:16.750: E/ACRA(12765):  at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
10-01 16:31:16.750: E/ACRA(12765):  at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
10-01 16:31:16.750: E/ACRA(12765):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
10-01 16:31:16.750: E/ACRA(12765):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:588)
10-01 16:31:16.750: E/ACRA(12765):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:563)
10-01 16:31:16.750: E/ACRA(12765):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:426)
10-01 16:31:16.750: E/ACRA(12765):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
10-01 16:31:16.750: E/ACRA(12765):  at android.content.res.Resources.loadDrawable(Resources.java:1981)
10-01 16:31:16.750: E/ACRA(12765):  at android.content.res.TypedArray.getDrawable(TypedArray.java:653)
10-01 16:31:16.750: E/ACRA(12765):  at android.view.View.<init>(View.java:1992)
10-01 16:31:16.750: E/ACRA(12765):  at android.view.View.<init>(View.java:1940)
10-01 16:31:16.750: E/ACRA(12765):  at android.view.ViewGroup.<init>(ViewGroup.java:286)
10-01 16:31:16.750: E/ACRA(12765):  at android.widget.LinearLayout.<init>(LinearLayout.java:120)
10-01 16:31:16.750: E/ACRA(12765):  ... 23 more
4

1 回答 1

0

在 android 中处理位图是一个非常大的问题,在您的情况下,设置背景资源最终只会在内部导致位图,所以,我的建议是:

  1. 将您的 Drawable 减小到合理的大小
  2. 关注支持多屏
于 2013-10-02T10:04:50.213 回答