Android Question file dialog

aeropic

Active Member
Licensed User
Longtime User
Hi all,
I'm trying to simply open a file dialog and it ends with a java exception. It crashes on the fd.show instruction.
What am I doing wrong?
Thanks
Alain

The code is :

B4X:
Dim fd As FileDialog
    Dim myFile As String  = ""
    Dim rp As RuntimePermissions
    Dim  i As Int
        rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
        wait for activity_PermissionResult (Permission As String, Result As Boolean)
        If Result Then
          '  ToastMessageShow("permission", False)
        End If
'    '---------------------------------------------------
'    'set file dialog input
    fd.FastScroll = True
    fd.FilePath = File.DirRootExternal
'ToastMessageShow(fd.FilePath, False)
    fd.FileFilter = ".csv"
Try
    i =    fd.Show("Select file", "Yes", "Cancel", "t", Null)
    
Catch
        Log(LastException)
End Try

and the exception is :
main$ResumableSub_btPhoto_Clickresume (java line: 1156)
java.lang.NoSuchFieldError: No instance field Text of type Ljava/lang/String; in class Lanywheresoftware/b4a/objects/SimpleListAdapter$SingleLineData; or its superclasses (declaration of 'anywheresoftware.b4a.objects.SimpleListAdapter$SingleLineData' appears in /data/app/my.app.DJI_Waypoints-eUnCj6gJ3RhA_YRLUorGKQ==/base.apk)
at anywheresoftware.b4a.agraham.dialogs.InputDialog$FileDialog.loadFileList(InputDialog.java:1786)
at anywheresoftware.b4a.agraham.dialogs.InputDialog$FileDialog.Show(InputDialog.java:1832)
at my.app.DJI_Waypoints.main$ResumableSub_btPhoto_Click.resume(main.java:1156)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
main$ResumableSub_btPhoto_Clickresume (java line: 1156)
java.lang.NoSuchFieldError: No instance field Text of type Ljava/lang/String; in class Lanywheresoftware/b4a/objects/SimpleListAdapter$SingleLineData; or its superclasses (declaration of 'anywheresoftware.b4a.objects.SimpleListAdapter$SingleLineData' appears in /data/app/my.app.DJI_Waypoints-eUnCj6gJ3RhA_YRLUorGKQ==/base.apk)
at anywheresoftware.b4a.agraham.dialogs.InputDialog$FileDialog.loadFileList(InputDialog.java:1786)
at anywheresoftware.b4a.agraham.dialogs.InputDialog$FileDialog.Show(InputDialog.java:1832)
at my.app.DJI_Waypoints.main$ResumableSub_btPhoto_Click.resume(main.java:1156)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
 

agraham

Expert
Licensed User
Longtime User
Firstly are you using the Dialogs2 library, it doesn'tlook like from the line numbers in the exception message. If not you should change to it, and use ShowAsync instead of Show which can cause problems in later versions of Android.

Dialogs2 library - an update to the original Dialogs library | B4X Programming Forum

Secondly that error is deep in the FileDialog private code and it is complaining that a String array is being assigned to a String variable. That should never happen as it is dealing with values returned from Android. Are you sure you that have PERMISSION_READ_EXTERNAL_STORAGE, your code above doesn't properly check for that.

If the error persists using Dialogs2 and ShowAsync then post the exception again so I can check the line numbers so I can maybe see where it is happening.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Also check that the FileDialog option in the demo app in the Dialogs2 download runs correctly and that you are targeting SDK 28. If you are targeting SDK2 9 you need a manifest entry as detailed here
android.jar / targetSdkVersion / minSdkVersion | B4X Programming Forum

If targeting SDK 30 you won't be able to get permission anyway and need to use External Storage class..
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…