Having a really weird OutOf Memory error in my app

2019-08-06 12:53发布

问题:

I have read pretty much all the related problems on stackoverflow but non seem to relate to the problem that I have. First of all, my app containts 160 plus images of approx. 180 - 300KB each with dimensions of 800 x 2000. Now on my samsung galaxy s2 (version 4.0.3) my app works fine no problems (testing it for about 20 minutes at a time) and on my galaxy young (version 2.3.6) still works like a charm (testing it in the same way) However, on my motorola xoom 2 tablet 10.1 inch(version4.0.4) not even 2 minutes in of testing the app it gives me java.lang.OutOfMemory error. Now on some threads ive read java.lang.OutOfMemoryError: bitmap size exceeds VM budget, but this doesn't relate to me as I am just getting java.lang.OutOfMemoryError. Here is the errors i am getting.

11-11 10:00:33.266: E/AndroidRuntime(5390): FATAL EXCEPTION: main
11-11 10:00:33.266: E/AndroidRuntime(5390): java.lang.OutOfMemoryError
11-11 10:00:33.266: E/AndroidRuntime(5390):     at   android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.graphics.BitmapFactory.decodeStream  (BitmapFactory.java:520)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at   android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:783)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.content.res.Resources.loadDrawable(Resources.java:1954)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.content.res.Resources.getDrawable(Resources.java:666)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.widget.ImageView.resolveUri(ImageView.java:570)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.widget.ImageView.setImageResource(ImageView.java:343)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at com.example.sample.app.Samples$5.onClick(Samples.java:77)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.view.View.performClick(View.java:3526)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.view.View$PerformClick.run    (View.java:14149)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.os.Handler.handleCallback (Handler.java:605)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.os.Handler.dispatchMessage (Handler.java:92)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.os.Looper.loop(Looper.java:137)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at android.app.ActivityThread.main(ActivityThread.java:4697)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at java.lang.reflect.Method.invokeNative(Native Method)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at java.lang.reflect.Method.invoke(Method.java:511)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
11-11 10:00:33.266: E/AndroidRuntime(5390):     at dalvik.system.NativeStart.main(Native Method)

I have asked my friend to test the app on his samsung tablet 10.1 inch (not sure of his version) to see if the same issue crops up. Havent heard from him yet, but once I do I will post here what the results are. So if he doesn't get a error can I safely assume that it is my tablet? or does my app not work properly on tablets?

Any suggestions?

回答1:

It's just a workaround what you find. It won't run on low memory devices. You have do reduce the size of your images to use less memory.

It's a well known problem in android, so google a little, and you find a lot of thread explaining how to deal with bitmaps in Android