Public Sub isDrive(Path As String) As Boolean
Dim FileJO As JavaObject
FileJO.InitializeStatic("java.io.File")
Dim FileSystemView As JavaObject
FileSystemView.InitializeStatic("javax.swing.filechooser.FileSystemView")
FileJO = FileSystemView.RunMethod("createFileObject", Array As String(Path))
Return FileSystemView.RunMethod("isDrive", Array As Object(FileJO))
End Sub
Sub AppStart (Args() As String)
Log(isDrive("C:\"))
End Sub
But with this code, I get this error :
main._isdrive (java line: 70)
java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:80)
at b4j.example.main._isdrive(main.java:70)
at b4j.example.main._appstart(main.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:26)
With this new code I am getting a different error :
B4X:
Public Sub isDrive(Path As String) As Boolean
Dim FileSystemView As JavaObject
FileSystemView.InitializeStatic("javax.swing.filechooser.FileSystemView")
FileSystemView = FileSystemView.RunMethod("getFileSystemView", Null)
Dim FileJO As JavaObject
FileJO = FileSystemView.RunMethod("createFileObject", Array As Object(Path))
Return FileSystemView.RunMethod("isDrive", Array As Object(FileJO))
End Sub
main._isdrive (java line: 70)
java.lang.IllegalAccessException: Class anywheresoftware.b4j.object.JavaObject can not access a member of class javax.swing.filechooser.WindowsFileSystemView with modifiers "public"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261)
at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253)
at java.lang.reflect.Method.invoke(Method.java:599)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:80)
at b4j.example.main._isdrive(main.java:70)
at b4j.example.main._appstart(main.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:26)
It will not work with JavaObject. It happens because the class returned is not public (only the interface). It should be possible to do it with jReflector library.