I get an error like this after successfully selecting a PDF file. Anyone know how to solve it?
2021-06-09 09:02:17.638 7277-7277/team.getherfolg.capstone E/AndroidRuntime: FATAL EXCEPTION: main
Process: team.getherfolg.capstone, PID: 7277
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.providers.downloads.documents/document/3964 flg=0x1 }} to activity {team.getherfolg.capstone/team.getherfolg.capstone.ui.pdfpreview.PDFPreviewActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:5237)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5278)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
Caused by: java.lang.NullPointerException
at team.getherfolg.capstone.ui.pdfpreview.PDFPreviewActivity.displayFromFile(PDFPreviewActivity.kt:172)
at team.getherfolg.capstone.ui.pdfpreview.PDFPreviewActivity.onActivityResult(PDFPreviewActivity.kt:150)
at android.app.Activity.dispatchActivityResult(Activity.java:8294)
This is for line code 172 (Starting from pdfView!!)
private fun displayFromFile(file: File) {
val uri = Uri.fromFile(File(file.absolutePath))
pdfFileName = getFileName(uri)
pdfView!!.fromFile(file)
.defaultPage(pageNumber)
.onPageChange(this)
.enableAnnotationRendering(true)
.onLoad(this)
.scrollHandle(DefaultScrollHandle(this))
.spacing(10)
.onPageError(this)
.load()
}
This is for line code 150 (Starting from displayFromFile(file))
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == FILE_PICKER_REQUEST_CODE && resultCode == RESULT_OK && data != null) {
val path: String = data.data.toString()
val file = File(path)
displayFromFile(file)
Log.d("Path: ", path)
pdfPath = path
Toast.makeText(this, "Picked file: $path", Toast.LENGTH_LONG).show()
}
}