0

谁能向我解释这个 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)
4

2 回答 2

0

如果您在运行时加载位图,您可以在使用此技术从设备读取它时将其缩小。如果您从res目录中加载它,您可能只需要使用图像编辑器将其缩小。无论哪种方式,图像显然太大而无法放入内存。

于 2013-04-17T14:29:54.647 回答
0

如我所见,您用于ImageView.setImageURI加载图像。

现在许多图像,尤其是由更高分辨率的相机(或手机)拍摄的图像,很容易占用比在屏幕上显示它们实际所需的空间更多的空间。

当您尝试将它们直接加载到位图中时,您的应用程序将耗尽内存并崩溃。另请参阅此问题或@oakleaf 的答案,以获取有关使用大型位图的 Android 开发人员培训的链接。

于 2013-04-17T14:34:02.183 回答