DImuthuUpe / AndroidPdfViewer

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

I am getting ANR after changing option menu #284

Open arpit999 opened 7 years ago

arpit999 commented 7 years ago

Process: com.production.hometech.ielts, PID: 28962 java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent com.github.barteksc.pdfviewer.PDFView.getParent()' on a null object reference at com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle$2.run(DefaultScrollHandle.java:106) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

1stmetro commented 7 years ago

obviously there is a null in there somewhere, it appears to be something to do with the scroll handler which i presume you tried to add?

why not post some code ?

arpit999 commented 7 years ago

Thank you for your valuable response, Sir, it happened sometime when I go to one fragment to another fragment quickly and I am using this library in three fragments I didn't get the exact position that's why I didn't add code. My app working fine now and one more thing sir when I load 1 MB pdf file in it, it quite slow responsive Is there any solution for that??

1stmetro commented 7 years ago

Slow response? Zoom and moving ? Loading ?

arpit999 commented 7 years ago

I added horizontal scroll in pdf while moving pdf it slow down.

1stmetro commented 7 years ago

you loaded the pdf in horzontial mode or changed the scroll option with the pdf already loaded and visible ?

arpit999 commented 7 years ago

Sorry I forgot to add my code see below my code

`  @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_writing, container, false);

        pdfView= (PDFView)rootView.findViewById(R.id.pdfView);

        displayFromAsset(SAMPLE_FILE);

        // Inflate the layout for this fragment
        return rootView;
    }

private void displayFromAsset(String assetFileName) {
        pdfFileName = assetFileName;

        pdfView.fromAsset(SAMPLE_FILE)
                .defaultPage(pageNumber)
                .enableSwipe(true)

                .swipeHorizontal(true)
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)
                .scrollHandle(new DefaultScrollHandle(getActivity()))
                .load();
    }

    @Override
    public void onPageChanged(int page, int pageCount) {
        pageNumber = page;
       getActivity(). setTitle(String.format("%s %s / %s", pdfFileName, page + 1, pageCount));
    }

    @Override
    public void loadComplete(int nbPages) {
        PdfDocument.Meta meta = pdfView.getDocumentMeta();
        printBookmarksTree(pdfView.getTableOfContents(), "-");

    }

    public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
        for (PdfDocument.Bookmark b : tree) {

            Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));

            if (b.hasChildren()) {
                printBookmarksTree(b.getChildren(), sep + "-");
            }
        }
    }`

XML file

`<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.hometech.production.ielts.fragment.WritingFragment">

<com.github.barteksc.pdfviewer.PDFView
    android:id="@+id/pdfView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

`

1stmetro commented 7 years ago

On first glance I would guess the on page changed event would slow it down when scrolling from page to page as it would lag changing title specially if you scroll fast.

Not tested any code, just my view at this point.

Don't forget the pdf viewer has a drag bar that can be added that shows the current page number and can make it easier to move down through the pages, 100 pages down instantly. I use numerous pdfs some a few hundred pages long, 25mb or more in size and I don't experience lag using the page bar, it's in the tutorial here on how to add this feature.

arpit999 commented 7 years ago

So I have to remove page changed event ?? For scroll fast ??

1stmetro commented 7 years ago

I would test it and see if it improves, I use several tablets and phones to test my apps to determine how efficient the app is on different cpu memory etc so maybe test on other devices if you have any.

arpit999 commented 7 years ago

Appreciate your help. I am egarly waiting for your response

On 10 May 2017 13:24, "1stmetro" notifications@github.com wrote:

I would test it and see if it improves, I use several tablets and phones to test my apps to determine how efficient the app is on different cpu memory etc so maybe test on other devices if you have any.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/barteksc/AndroidPdfViewer/issues/284#issuecomment-300404628, or mute the thread https://github.com/notifications/unsubscribe-auth/AMmg5fmGo_l3DstfuEgJt3_4e3Cbrrm8ks5r4W06gaJpZM4NSm6E .