加载大型PDF时应用程序出现问题

时间:2017-11-28 13:02:50

标签: android pdf out-of-memory

任何人都知道如何在Android中加载大型PDF文件?我使用“android-pdf-viewer”来加载那种文件。它适用于文件较小的情况。但是一旦文件太大(例如150M),就会引发OOM异常。

11-28 21:07:43.596 7844-8419/com.example.caoweizhao.readerapp E/art: Out 
of memory: Heap Size=192MB, Allocated=83MB, Capacity=192MB
11-28 21:07:43.596 7844-8419/com.example.caoweizhao.readerapp W/art: 
Throwing OutOfMemoryError "Failed to allocate a 134209548 byte 
allocation with 16777216 free bytes and 108MB until OOM"
11-28 21:07:43.607 7844-7844/com.example.caoweizhao.readerapp E/PDFView: load pdf error
                                                                     java.lang.OutOfMemoryError: Failed to allocate a 134209548 byte allocation with 16777216 free bytes and 108MB until OOM
                                                                         at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
                                                                         at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
                                                                         at com.github.barteksc.pdfviewer.util.Util.toByteArray(Util.java:37)
                                                                         at com.github.barteksc.pdfviewer.source.InputStreamSource.createDocument(InputStreamSource.java:37)
                                                                         at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:53)
                                                                         at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:25)
                                                                         at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                                         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                         at java.lang.Thread.run(Thread.java:818)

11

1 个答案:

答案 0 :(得分:3)

AndroidManifest.xml 文件中,在应用标记中添加android:largeHeap="true"