B4J Question DirectoryChooser Error

techknight

Well-Known Member
Licensed User
I cannot get DirectoryChooser to work. I have never used it before, but I found a post by DonManfred in another thread with an example. Sadly one of the variables in his example isnt declared, so I guessed what it was.

But it doesnt work. I keep getting this:
java.lang.IllegalArgumentException: Folder parameter must be a valid folder

Here is my code:
B4X:
Sub cmdChooseMediaDIR_Click
    Dim dirchoose As DirectoryChooser
    dirchoose.Initialize
    If txtMediaDIR.Text = "" Or Not(File.Exists(File.GetFileParent(txtMediaDIR.Text), "")) Then
        txtMediaDIR.Text = File.DirApp
    End If
    dirchoose.InitialDirectory = txtMediaDIR.Text
    dirchoose.Title = "Set Folder to bla bla bla"
    dirchoose.Show(frm)
End Sub
Now, If I comment out the InitialDirectory, it works fine. However, when the dialog is showing, This happens in my logcat:
B4X:
Waiting for debugger to connect...
Program started.
Trying to connect
Unexpected event (missing RaiseSynchronousEvents): AFTER_SLEEP
java.lang.Exception: Stack trace
    at java.lang.Thread.dumpStack(Thread.java:1336)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:199)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:135)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:84)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$3.run(BA.java:246)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinCommonDialogs._showFolderChooser(Native Method)
    at com.sun.glass.ui.win.WinCommonDialogs.showFolderChooser_impl(WinCommonDialogs.java:70)
    at com.sun.glass.ui.win.WinApplication.staticCommonDialogs_showFolderChooser(WinApplication.java:304)
    at com.sun.glass.ui.CommonDialogs.showFolderChooser(CommonDialogs.java:226)
    at com.sun.javafx.tk.quantum.QuantumToolkit.showDirectoryChooser(QuantumToolkit.java:1534)
    at javafx.stage.DirectoryChooser.showDialog(DirectoryChooser.java:103)
    at anywheresoftware.b4j.objects.DirectoryChooserWrapper.Show(DirectoryChooserWrapper.java:43)
    at md.cms3knorthmont.settingswindow._cmdchooselogodir_click(settingswindow.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:628)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:98)
    at anywheresoftware.b4a.BA$1.run(BA.java:215)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
    at java.lang.Thread.run(Thread.java:748)
Error connecting.
Trying to connect
Error connecting.
Trying to connect
Thoughts?
 
Last edited:

stevel05

Expert
Licensed User
For the first problem, use File.Isdirectory to check if it's a valid value to pass to the File Chooser (or Not(File.isdirectory(...)) in your context).

For the second, what version of Java are you using? I haven't seen this on 8.
 

techknight

Well-Known Member
Licensed User
Java 8 1.8.1

Also, let me clarify. On the 2nd part. it only happened in DEBUG mode. I tried release mode after I had already made my post, and that error did not show up.
 

techknight

Well-Known Member
Licensed User
Probably not because there are resumable sub events happening in the background, or sleeps, etc. Something is triggering it, but I am not good at that stack pointer output from java to be able to know what caused it.

Could be a mistake on my part on how I am handling resumablesubs, But again I use them just about everywhere so I dont know exactly whicn one might be triggering the above error.

But again it only does this in debug mode. I am wondering if the stack isnt getting blown away somehow and the resumable sub tries to fire and it gets lost? Who knows.
 

stevel05

Expert
Licensed User
Ah OK. Then I probably can't help much either. Is AFTER_SLEEP one of your Subs?
 
Last edited:

ThRuST

Well-Known Member
Licensed User
Try move the file exists checking

B4X:
If txtMediaDIR.Text = "" Or Not(File.Exists(File.GetFileParent(txtMediaDIR.Text), "")) Then
        txtMediaDIR.Text = File.DirApp
    End If

after this

B4X:
dirchoose.Show(frm)
You'be been ThRuSTed, Cheers :cool:
 

ThRuST

Well-Known Member
Licensed User
Here's a structure I made which works well

B4X:
Sub BtnPath1_Click

    Dim dc As DirectoryChooser
    dc.Initialize
    'dc.InitialDirectory = ""
    dc.Title = "Please select a folder"
    Dim folder As String
    folder = dc.Show(MainForm)

    If folder <> "" Then

                ' Store folder path
                LblFolder1.Text = folder

    Else

                ' Folder path empty
                LblFolder1.Text = "Empty"

    End If

               ' Store new path
               Folderpath = LblFolder1.Text
        
End Sub
 

techknight

Well-Known Member
Licensed User
Only thing I ever saw was MQTT crashing out, saying its already connected when it tried to connect again for some reason. But that I think is completely unrelated.
 
Top