我正在将此库用于AndroidPdfViewer https://github.com/barteksc/AndroidPdfViewer
E/PDFView: load pdf error
java.lang.NullPointerException
at com.github.barteksc.pdfviewer.util.Util.toByteArray(Util.java:36)
at com.github.barteksc.pdfviewer.source.InputStreamSource.createDocument(InputStreamSource.java:37)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:49)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:25)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
在这里,我在此行上得到nullPointer异常。
inputStream=new BufferedInputStream(urlConnection.getInputStream());
答案 0 :(得分:1)
这似乎不是库错误,因为这是由于null参数引起的NullPointer升高。您的PDFViwer无法打开文件,因此将引发空指针异常。您可以检查原因代码。您应遵循最佳做法,以防止出现这种情况。
首先检查连接,它不能为空。您可以按照下面给出的?
三元运算符进行检查。
// InputStream in = conn.getInputStream();
// check for the null connection first, it's possible that connection could not be made before opening the InputStream.
InputStream in = (conn != null) ? conn.getInputStream() : null;