我正在创建一个Android应用。我希望它能在两个方向上发挥作用。当我在横向模式下运行它时效果很好,但在将其更改为纵向时,应用程序停止了。我打开它会正常工作。这是我的问题。当我改变方向时。第一次出现错误。帮我解决这个问题。
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: java.lang.RuntimeException: An error occured while executing doInBackground()
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at android.os.AsyncTask$3.done(AsyncTask.java:299)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:239)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.lang.Thread.run(Thread.java:856)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: Caused by: java.lang.OutOfMemoryError
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:302)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at com.infizoom.smartselfie2.Helper.decodeSampledBitmapFromPath(Helper.java:32)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at com.infizoom.smartselfie2.FrameActivity.LoadImagesFromLocalDb(FrameActivity.java:195)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at com.infizoom.smartselfie2.FrameActivity$LoadImagesIntoLocal.doInBackground(FrameActivity.java:136)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at com.infizoom.smartselfie2.FrameActivity$LoadImagesIntoLocal.doInBackground(FrameActivity.java:114)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
11-05 16:40:44.010 10204-10250/com.infizoom.smartselfie2 E/AndroidRuntime: at java.lang.Thread.run(Thread.java:856)
答案 0 :(得分:1)
在更改方向后重新创建活动时,您将收到OutOfMemory异常。
我猜你的FrameActivity,你在每次创建活动时泄漏位图,不允许GC释放足够的内存。