miguelpruivo / flutter_file_picker

File picker plugin for Flutter, compatible with mobile (iOS & Android), Web, Desktop (Mac, Linux, Windows) platforms with Flutter Go support.
MIT License
1.35k stars 672 forks source link

[Bug] Null exception error on android #1604

Closed Lilian-C closed 1 week ago

Lilian-C commented 1 month ago

Hello,

Firebase is showing this error on our production app:

Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=null} to activity {[...]flutter.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.content.Intent.getData()' on a null object reference at android.app.ActivityThread.deliverResults(ActivityThread.java:5815) at android.app.ActivityThread.handleSendResult(ActivityThread.java:5854) at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:69) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:60) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:231) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:152) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:93) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2595) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8592) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.content.Intent.getData()' on a null object reference at com.mr.flutter.plugin.filepicker.FilePickerDelegate.onActivityResult(FilePickerDelegate.java:15) at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEngineConnectionRegistry.java:25) at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult(FlutterEngineConnectionRegistry.java:14) at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:51) at io.flutter.embedding.android.FlutterFragment.onActivityResult(FlutterFragment.java:10) at io.flutter.embedding.android.FlutterFragmentActivity.onActivityResult(FlutterFragmentActivity.java:5) at android.app.Activity.internalDispatchActivityResult(Activity.java:9340) at android.app.Activity.dispatchActivityResult(Activity.java:9324) at android.app.ActivityThread.deliverResults(ActivityThread.java:5807) at android.app.ActivityThread.handleSendResult(ActivityThread.java:5854) at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:69) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:60) at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:231) at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:152) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:93) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2595) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.app.ActivityThread.main(ActivityThread.java:8592) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

I'm not sure, but it looks like a null safety error in the FilePickerDelegate.java file, on the data.getData() call inside the onActivityResult method.

rohansohonee1 commented 1 month ago

Faced same issue:

          Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2343, result=-1, data=null} to activity {com.agendaboa.app/com.agendaboa.app.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.content.Intent.getData()' on a null object reference
       at android.app.ActivityThread.deliverResults(ActivityThread.java:5946)
       at android.app.ActivityThread.handleSendResult(ActivityThread.java:5985)
       at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8751)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
          Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri android.content.Intent.getData()' on a null object reference
       at com.mr.flutter.plugin.filepicker.FilePickerDelegate.onActivityResult(FilePickerDelegate.java:89)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEngineConnectionRegistry.java:774)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult(FlutterEngineConnectionRegistry.java:422)
       at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:857)
       at io.flutter.embedding.android.FlutterFragment.onActivityResult(FlutterFragment.java:1251)
       at io.flutter.embedding.android.FlutterFragmentActivity.onActivityResult(FlutterFragmentActivity.java:653)
       at android.app.Activity.dispatchActivityResult(Activity.java:8659)
       at android.app.ActivityThread.deliverResults(ActivityThread.java:5939)
       at android.app.ActivityThread.handleSendResult(ActivityThread.java:5985)
       at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
       at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loopOnce(Looper.java:226)
       at android.os.Looper.loop(Looper.java:313)
       at android.app.ActivityThread.main(ActivityThread.java:8751)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Device Brand:Samsung Model:Galaxy M31 Orientation:Portrait RAM free: 1.22 GB Disk free: 33.86 GB Operating System Version:Android 12 Orientation:Portrait Rooted: No

file_picker: 8.0.5
github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 7 days with no activity.

rohansohonee1 commented 1 month ago

@miguelpruivo Please check this issue when you have the time.

Lilian-C commented 1 month ago

Hey @miguelpruivo , I made a PR for this issue: https://github.com/miguelpruivo/flutter_file_picker/pull/1615

Lilian-C commented 1 month ago

FYI @rohansohonee1 , PR https://github.com/miguelpruivo/flutter_file_picker/pull/1615 was merged, it's available on version 8.1.3 of flutter_file_picker

github-actions[bot] commented 3 weeks ago

This issue is stale because it has been open for 7 days with no activity.

github-actions[bot] commented 1 week ago

This issue was closed because it has been inactive for 14 days since being marked as stale.