有人可以向我解释这个LogCat输出以及如何解决它吗?我正用我的手机(三星Galaxy Nexus)测试我的Android应用程序,就像那样;系统强行扣留并在LogCat中打印出来......
04-17 09:43:09.189: E/AndroidRuntime(1194): FATAL EXCEPTION: main
04-17 09:43:09.189: E/AndroidRuntime(1194): java.lang.OutOfMemoryError
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:527)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:301)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:326)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.graphics.drawable.Drawable.createFromPath(Drawable.java:894)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.ImageView.resolveUri(ImageView.java:638)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.ImageView.setImageURI(ImageView.java:379)
04-17 09:43:09.189: E/AndroidRuntime(1194): at tian.proto.galeriaImagenes$ImageAdapter.getView(galeriaImagenes.java:169)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:193)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
04-17 09:43:09.189: E/AndroidRuntime(1194): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.View.measure(View.java:15172)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.Choreographer.doFrame(Choreographer.java:525)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.os.Handler.handleCallback(Handler.java:615)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.os.Handler.dispatchMessage(Handler.java:92)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.os.Looper.loop(Looper.java:137)
04-17 09:43:09.189: E/AndroidRuntime(1194): at android.app.ActivityThread.main(ActivityThread.java:4899)
04-17 09:43:09.189: E/AndroidRuntime(1194): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 09:43:09.189: E/AndroidRuntime(1194): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 09:43:09.189: E/AndroidRuntime(1194): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-17 09:43:09.189: E/AndroidRuntime(1194): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
04-17 09:43:09.189: E/AndroidRuntime(1194): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
如果您在运行时加载位图,则可以在使用this technique从设备读取位图时将其缩小。如果您从res
目录加载它,您可能只需要使用图像编辑器将其缩小。无论哪种方式,图像显然太大而无法适应记忆。
答案 1 :(得分:0)
如我所见,您使用ImageView.setImageURI
加载图片。
现在许多图像,特别是高分辨率相机(或手机)拍摄的图像,很容易占用比在屏幕上显示它们所需的更多空间。
当您尝试将它们直接加载到位图时,您的应用程序将耗尽内存并崩溃。 另请参阅此question或@oakleaf的答案,获取有关使用大型位图的Android开发人员培训的链接。