B4J Question Open a file with the associated program

kohle

Active Member
Licensed User
Longtime User
Hi,
in an other language I use the windows api function :
ShellExecuteA( hwnd, lpOperation, lpFile, lpParameters , lpDirectory, nShowCmd )

B4X:
ulong nShowCmd = 1 // Normal open
setNull(lpOperation)

ShellExecuteA( hwnd,   lpOperation,  "c:\mydoc\test.doc",   "" ,   "",   nShowCmd )

How can I open a file in B4J with the associated program without knowing name and location of the program.

Thanks
 

kohle

Active Member
Licensed User
Longtime User
I get an error,

B4X:
Waiting for debugger to connect...
Program started.
file:/C:/000_test/new_Document2.docx
Error occurred on line: 152
java.lang.NullPointerException
    at anywheresoftware.b4j.objects.JFX.ShowExternalDocument(JFX.java:84)
    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.runVoidMethod(Shell.java:656)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:232)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    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:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.main(main.java:29)
 
Upvote 0

kohle

Active Member
Licensed User
Longtime User
I think with the cmd the path variable of windows must be set to the program.

I tried it like this with the UI version : Dont load the form, start the external program and after this I close the app with the ExitApplication command.
Looks for me the same like an non-ui app.

Thanks to all.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…