B4J Question Command Line Args handle none or multiple


Licensed User
Hi everyone,

Unsure where I'm going wrong here, I have a program that runs on ~1500 remote devices (and growing) and am looking to add into the next version a way to stop a reset on start up if we're manually doing so while SSH-ing in. Thanks to the historical devices getting programs called from other sources it has to be able to be called with or without the command line args.

sudo java -jar Program1.jar 1

CmdLn Args:
    Dim TVNotRun As Int = 0
End Sub

Sub AppStart (Args() As String)
    If Args(0).length <> 0 Then
        TVNotRun = Args(0)
    End If
    If TVNotRun = 0 Then
        Log("TVNOTRUN INT 0")
    Else If TVNotRun = 1 Then
        Log("TVNOTRUN INT 1")
    End If
    'Start Program
End Sub

I get a error when run without cmd ln args,
CmdLn Args error:
main._appstart (java line: 608)
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at b4j.collator1.main._appstart(main.java:608)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.collator1.main.main(main.java:28)

I'm Probably being slow here...

Is this something that is not doable or am i missing something simple here?

However any helps greatly appreciated!


Licensed User
Longtime User
If Args(0).length <> 0 Then
        TVNotRun = Args(0)
End If
needs to be
If Args.length <> 0 Then
        TVNotRun = Args(0)
End If
Upvote 0