AndroidPdfViewer
AndroidPdfViewer copied to clipboard
NullPointerException in DragPinchManager in 3.0.0-beta.5
I'm getting the following error on version 3.0.0-beta.5. I was unable to reproduce it on my phone, but I got Fabric reports from several different devices (Xiaomi, Huawei, Samsung) on different Android versions (5.0, 6.0, 7.0):
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int com.github.barteksc.pdfviewer.PdfFile.getPageAtOffset(float, float)' on a null object reference
at com.github.barteksc.pdfviewer.DragPinchManager.checkLinkTapped(DragPinchManager.java:87)
at com.github.barteksc.pdfviewer.DragPinchManager.onSingleTapConfirmed(DragPinchManager.java:68)
at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:312)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
it maybe worth posting some code, to demonstrate what the issue could be...
Don't believe i get this error...
I'm not sure that the code will help (the stack trace doesn't include any of my code). This error occurs once in a few thousand users, but here's what I have in my Activity:
class PDFActivity : BaseActivity(), AnkoLogger {
private var activePage: Int = 0
private lateinit var pdfView: PDFView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activePage = savedInstanceState?.getInt(EXTRA_PAGE) ?: 0
pdfView = ankoView({ context -> PDFView(context, null) }, theme = 0) {}
}
override fun onResume() {
super.onResume()
intent.data?.let {
pdfView.loadDocument(it, activePage)
} ?: finishWithError()
}
private fun PDFView.loadDocument(uri : Uri, defaultPage: Int) {
fromUri(uri)
.enableAntialiasing(true)
.defaultPage(defaultPage)
.onRender { mbPages -> pdfView.fitToWidth(defaultPage) }
.onPageChange { page, pagesCount ->
info("$page/$pagesCount")
activePage = page
}
.onPageScroll { page, _ -> activePage = page }
.onError { throwable -> finishWithError(throwable) }
.onPageError { _, throwable -> finishWithError(throwable) }
.load()
}
private fun finishWithError(throwable: Throwable? = null) {
throwable?.let { error("Error in PDF view", it) }
toast(R.string.error_pdf_uri)
finish()
}
override fun onPause() {
super.onPause()
pdfView.recycle()
}
override fun onSaveInstanceState(outState: Bundle?) {
super.onSaveInstanceState(outState)
outState?.putInt(EXTRA_PAGE, activePage)
}
}
I think that some null checks in DragPinchManager
should be enough to prevent this from happening.
i have this too one time on android 4.3.
@1stmetro @sczerwinski @Flamedek I am getting the same crash on 3.1.0-beta.1 on Galaxy S7 with version 7.0. I am unable to reproduce it. Below is the stack trace:
Fatal Exception: java.lang.NullPointerException Attempt to invoke virtual method 'int com.github.barteksc.pdfviewer.PdfFile.getPageAtOffset(float, float)' on a null object reference com.github.barteksc.pdfviewer.DragPinchManager.checkLinkTapped (DragPinchManager.java:88) com.github.barteksc.pdfviewer.DragPinchManager.onSingleTapConfirmed (DragPinchManager.java:69) android.view.GestureDetector$GestureHandler.handleMessage (GestureDetector.java:312) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:154) android.app.ActivityThread.main (ActivityThread.java:6692) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)
@1stmetro @sczerwinski @Flamedek I am getting the same crash on 3.1.0-beta.1 on Galaxy S7 with version 7.0. I am
so do you resolved this issue, may i know which version?
@viveksaruk @whhotw It's quite an old issue. Unfortunately, I no longer have access to the code in which I used AndroidPdfViewer.