TalbotGooday / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
31 stars 23 forks source link

NullPointerException in PDFView.loadComplete #1

Closed madmas closed 4 years ago

madmas commented 4 years ago

After loading an PDF, I get this exception:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Attempt to invoke virtual method 'boolean java.lang.Thread.isAlive()' on a null object reference
System.err: 
System.err: StackTrace:
System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Thread.isAlive()' on a null object reference
System.err:     at com.github.barteksc.pdfviewer.PDFView.loadComplete(PDFView.java:756)
System.err:     at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:80)
System.err:     at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:27)
System.err:     at android.os.AsyncTask.finish(AsyncTask.java:667)
System.err:     at android.os.AsyncTask.-wrap1(AsyncTask.java)
System.err:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:684)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
System.err:     at android.os.Looper.loop(Looper.java:241)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6274)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

From my point of view this state should not be possible as the referenced object is initialized in the constructor - but, it is.

madmas commented 4 years ago

@TalbotGooday Thank a lot for the suggestion, I treid to patch it as well but inserted

 if(renderingHandlerThread == null){
            renderingHandlerThread = new HandlerThread("PDF renderer");
        }

instead of a return to re-initialize it as it is initialized in the constructor. I was able to verify it in the context the error occured for me and it worked fine - do you want a PR for it or do you have thoughts about it?

TalbotGooday commented 4 years ago

@madmas Please, create a PR. I can't fix this now 'cause I want to refactor the library on which based this one. I need some time to figure out how to build native code)

madmas commented 4 years ago

@TalbotGooday here it is ;-) I would be great if you can forge a release after it is merged 😇

TalbotGooday commented 4 years ago

@madmas Thank you) I'll try to make a release ASAP)

TalbotGooday commented 4 years ago

Merged, fixed, released. Version 3.1.0-beta.3 is waiting for you

madmas commented 4 years ago

@TalbotGooday it looks to me like something went wrong with the release :( I cannot get it from https://jitpack.io/com/github/TalbotGooday/AndroidPdfViewer/3.1.0-beta.3/ - does it work for you?

TalbotGooday commented 4 years ago

@madmas Yeah. There was some kind of a bug with the jitpack. Try again now

madmas commented 4 years ago

@TalbotGooday thanks a lot, works now.