-
Notifications
You must be signed in to change notification settings - Fork 147
Application crashes when displaying a PDFViewer widget #100
Comments
I have also faced this issue today after upgrading to Flutter 2.8.1 Thanks for the fix @ncdm-stldr |
Thanks for the fix ! |
Where this file "FlutterPluginPdfViewerPlugin.java" is exist in project? |
It's not in your project. It's in the package. Change your code according to that PR and hot restart your app. The error will be gone! |
Thanks. That fixed the crash for me. Hope it gets merged soon. |
Thanks. fixed !! |
Application crash with the following exception when displaying PDFViewer widget
[ +181 ms] I/System.out(25219): Already closed [ ] W/System.err(25219): java.lang.IllegalStateException: Already closed [ +6 ms] W/System.err(25219): at android.graphics.pdf.PdfRenderer.throwIfClosed(PdfRenderer.java:270) [ ] W/System.err(25219): at android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:187) [ ] W/System.err(25219): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.getPage(FlutterPluginPdfViewerPlugin.java:206) [ ] W/System.err(25219): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin.access$100(FlutterPluginPdfViewerPlugin.java:31) [ ] W/System.err(25219): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin$1.run(FlutterPluginPdfViewerPlugin.java:84) [ ] W/System.err(25219): at android.os.Handler.handleCallback(Handler.java:883) [ ] W/System.err(25219): at android.os.Handler.dispatchMessage(Handler.java:100) [ ] W/System.err(25219): at android.os.Looper.loop(Looper.java:214) [ ] W/System.err(25219): at android.os.HandlerThread.run(HandlerThread.java:67) [ ] D/PdfViewerPlugin(25219): Retrieving page failed. [ ] D/AndroidRuntime(25219): Shutting down VM [ ] E/AndroidRuntime(25219): FATAL EXCEPTION: main [ ] E/AndroidRuntime(25219): Process: com.example.example, PID: 25219 [ ] E/AndroidRuntime(25219): java.lang.IllegalStateException: Reply already submitted [ ] E/AndroidRuntime(25219): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:286) [ ] E/AndroidRuntime(25219): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:267) [ ] E/AndroidRuntime(25219): at pt.tribeiro.flutter_plugin_pdf_viewer.FlutterPluginPdfViewerPlugin$1$2.run(FlutterPluginPdfViewerPlugin.java:92) [ ] E/AndroidRuntime(25219): at android.os.Handler.handleCallback(Handler.java:883) [ ] E/AndroidRuntime(25219): at android.os.Handler.dispatchMessage(Handler.java:100) [ ] E/AndroidRuntime(25219): at android.os.Looper.loop(Looper.java:214) [ ] E/AndroidRuntime(25219): at android.app.ActivityThread.main(ActivityThread.java:7399) [ ] E/AndroidRuntime(25219): at java.lang.reflect.Method.invoke(Native Method) [ ] E/AndroidRuntime(25219): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502) [ ] E/AndroidRuntime(25219): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) [ +12 ms] E/flutter (25219): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getPage on channel flutter_plugin_pdf_viewer) [ ] E/flutter (25219): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:165:7) [ ] E/flutter (25219): <asynchronous suspension> [ ] E/flutter (25219): #1 PDFDocument.get (package:advance_pdf_viewer/src/document.dart:97:18) [ ] E/flutter (25219): <asynchronous suspension> [ ] E/flutter (25219): #2 _PDFViewerState._loadPage (package:advance_pdf_viewer/src/viewer.dart:151:18) [ ] E/flutter (25219): <asynchronous suspension> [ ] E/flutter (25219): [ +29 ms] I/Process (25219): Sending signal. PID: 25219 SIG: 9 [ +90 ms] Service protocol connection closed. [ ] Lost connection to device.
Steps to reproduce
I don't know if the issue is easy to reproduce, or if it happens is my specific situation.
Device plateform: Android
My flutter version: Flutter 2.8.1
Dart version: Dart 2.15.1
plugin version: advance_pdf_viewer: ^2.0.1
I simply use the PDFViewer in a regular fashion.
How to solve
After investigation the error seems two-folds but is easy to solve:
In file FlutterPluginPdfViewerPlugin.java
The
if (pageResult == null)
should be followed by a else block. This prevents using result two times which results injava.lang.IllegalStateException: Reply already submitted
, because the method channel cannot receive two answers.Adding the else block prevents the application from crashing in my case.
However, in my situation
getPage
still returns null, and 'result.notImplemented();' is called, which should not be the case.So the second thing to fix is the
getPage
method which begin with:try (PdfRenderer renderer = new PdfRenderer(getPdfFile(filePath))) {
This ensure the renderer is closed at the end of the try-catch. However, the renderer is also closed inside the try-catch, which should not be the case.
After removing the
renderer.close();
call, I don't have the issue anymore.I will create a pull request to provide the fix I just descibed above.
The text was updated successfully, but these errors were encountered: