为什么我在模拟器上遇到 Inflate 异常,但在我的 Droid 上却没有?
我的代码在我的 Motorola Droid 上运行良好,但是当我在模拟器上运行它时,我得到以下堆栈跟踪:
07-05 14:29:23.035: ERROR/AndroidRuntime(237): Uncaught handler: thread main exiting due to uncaught exception
07-05 14:29:23.075: ERROR/AndroidRuntime(237): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thinknao.wordlands/com.thinknao.wordlands.OptionsPage}: android.view.InflateException: Binary XML file line #16: Error inflating class java.lang.reflect.Constructor
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class java.lang.reflect.Constructor
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): Caused by: java.lang.reflect.InvocationTargetException
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.widget.Button.<init>(Button.java:65)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
My code runs fine on my Motorola Droid but when i run it on the emulator i get this stack trace:
07-05 14:29:23.035: ERROR/AndroidRuntime(237): Uncaught handler: thread main exiting due to uncaught exception
07-05 14:29:23.075: ERROR/AndroidRuntime(237): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thinknao.wordlands/com.thinknao.wordlands.OptionsPage}: android.view.InflateException: Binary XML file line #16: Error inflating class java.lang.reflect.Constructor
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class java.lang.reflect.Constructor
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): Caused by: java.lang.reflect.InvocationTargetException
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.widget.Button.<init>(Button.java:65)
07-05 14:29:23.075: ERROR/AndroidRuntime(237): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-05 14:29:23.075: ERROR/AndroidRuntime(237): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不查看代码和布局,很难准确判断,但内存不足。它看起来与位图对象的加载有关,该对象在布局文件的第 16 行引用。
我建议您要么使用非常大的图像文件;您使用了大量图像;或两者的组合。
它在 Droid 上运行但不在模拟器上运行的原因很可能是模拟器配置的内存比手机少。您可以在 AVD 管理器中更改模拟器设置。
It's difficult to be exact without seeing your code and layout, but you are running out of memory. It looks to be concerned with the loading of a bitmap object, one that is referenced on line 16 of your layout file.
I would suggest that either you are using a very large image file; you are using lots of images; or a combination of the two.
The reason that it runs on the Droid but not on the emulator is, most likely, that the emulator has been configured with less memory than the phone. You can change your emulator settings in the AVD manager.