-3

我正在为所有 android 设备开发一个应用程序。它在所有设备上运行良好,我在三星 Galaxy S1、Galaxy Nexus、摩托罗拉 Xoom、HTC One 以及亚马逊 Kindle Fire 上进行了测试。它在所有设备上都能完美运行,但是当我尝试在 Nexus 7 上使用它时,它崩溃了,并且在日志中显示内存不足错误。我尝试System.gc();在 Activity#onPause() 方法中使用,但徒劳无功。应用程序中存在替代的可绘制对象和布局。请帮我解决这个问题。此问题仅特定于 Nexus 7。下面是堆栈跟踪:

    12-05 16:42:45.625: E/AndroidRuntime(8759): FATAL EXCEPTION: main
12-05 16:42:45.625: E/AndroidRuntime(8759): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.app/com.android.app.activity.MyListActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.os.Looper.loop(Looper.java:137)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.ActivityThread.main(ActivityThread.java:5039)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at java.lang.reflect.Method.invokeNative(Native Method)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at java.lang.reflect.Method.invoke(Method.java:511)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at dalvik.system.NativeStart.main(Native Method)
12-05 16:42:45.625: E/AndroidRuntime(8759): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.Activity.setContentView(Activity.java:1881)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at com.android.app.activity.MyListActivity.onCreate(MyListActivity.java:39)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.Activity.performCreate(Activity.java:5104)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
12-05 16:42:45.625: E/AndroidRuntime(8759):     ... 11 more
12-05 16:42:45.625: E/AndroidRuntime(8759): Caused by: java.lang.reflect.InvocationTargetException
12-05 16:42:45.625: E/AndroidRuntime(8759):     at java.lang.reflect.Constructor.constructNative(Native Method)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
12-05 16:42:45.625: E/AndroidRuntime(8759):     ... 23 more
12-05 16:42:45.625: E/AndroidRuntime(8759): Caused by: java.lang.OutOfMemoryError
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.content.res.Resources.loadDrawable(Resources.java:1965)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.View.<init>(View.java:3328)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.view.ViewGroup.<init>(ViewGroup.java:431)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.widget.LinearLayout.<init>(LinearLayout.java:176)
12-05 16:42:45.625: E/AndroidRuntime(8759):     at android.widget.LinearLayout.<init>(LinearLayout.java:172)
12-05 16:42:45.625: E/AndroidRuntime(8759):     ... 26 more

提前致谢。

4

1 回答 1

5

是的,我也遇到过这个问题,但没有找到有效的解决方案,但您可以尝试android:largeHeap="true"在应用程序级别的清单中使用

于 2012-12-05T11:55:01.583 回答