编程语言
首页 > 编程语言> > 加载大PDF时应用程序崩溃

加载大PDF时应用程序崩溃

作者:互联网

有人知道如何在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

解决方法:

在您的AndroidManifest.xml文件中,在应用程序标记中添加android:largeHeap =“ true”

标签:pdf,out-of-memory,android
来源: https://codeday.me/bug/20191110/2014667.html