我正在为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());发布于 2018-12-05 12:51:39
这似乎不是一个库错误,因为这是由于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;https://stackoverflow.com/questions/53613846
复制相似问题