DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.18k stars 1.91k forks source link

Sporadic crash in DefaultScrollHandle.setScroll() on orientation change #192

Open majkimester opened 7 years ago

majkimester commented 7 years ago

To avoid NullPointerException in DefaultScrollHandle.setScroll() please add an additional check:

    @Override
    public void setScroll(float position) {
        if (!shown()) {
            show();
        } else {
            handler.removeCallbacks(hidePageScrollerRunnable);
        }
        //  add additional check to avoid NPE on orientation change
        if (isPDFViewReady()) {
            setPosition((pdfView.isSwipeVertical() ? pdfView.getHeight() : pdfView.getWidth()) * position);
        }
    }
dsrees commented 7 years ago

We are experiencing this in our product. Related stack trace.

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.github.barteksc.pdfviewer.PDFView.isSwipeVertical()' on a null object reference
    at com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle.setScroll(DefaultScrollHandle.java:113)
    at com.github.barteksc.pdfviewer.PDFView.moveTo(PDFView.java:925)
    at com.github.barteksc.pdfviewer.PDFView.moveTo(PDFView.java:846)
    at com.github.barteksc.pdfviewer.PDFView.onSizeChanged(PDFView.java:539)
    at android.view.View.sizeChange(View.java:17682)