Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.12k
stars
1.89k
forks
source link
Attempt to invoke virtual method 'com.github.barteksc.pdfviewer.PDFView$Configurator com.github.barteksc.pdfviewer.PDFView.fromFile(java.io.File)' on a null object reference the second time i try to open the same pdf file #734
I download the pdf file in the files folder, the first time i display it in my fragment its ok but when i go back to open it again it crashes with the error: Attempt to invoke virtual method 'com.github.barteksc.pdfviewer.PDFView$Configurator com.github.barteksc.pdfviewer.PDFView.fromFile(java.io.File)' on a null object reference.
The pdf file exists on the storage as i can see it in the file explorer and it can be read so why i cannot open it a second time???
if (filePath != null) {
val file = File(context!!.filesDir,filePath)
if (file.exists() && file.canRead()) {
pdfView.fromFile(file).load() //crash says file its null, but in the debugger says its not!!!!
}
}
Edit: I solved it by wrapping the code above in the thread { } closure.
I download the pdf file in the files folder, the first time i display it in my fragment its ok but when i go back to open it again it crashes with the error: Attempt to invoke virtual method 'com.github.barteksc.pdfviewer.PDFView$Configurator com.github.barteksc.pdfviewer.PDFView.fromFile(java.io.File)' on a null object reference. The pdf file exists on the storage as i can see it in the file explorer and it can be read so why i cannot open it a second time???
Edit: I solved it by wrapping the code above in the thread { } closure.