When I use that code on main file works fine:
when I want move to a separate class / module as:
getting error of:
java.lang.NullPointerException
at anywheresoftware.b4j.objects.Shell$1.onProcessFailed(Shell.java:146)
at org.apache.commons.exec.DefaultExecutor$1.run(DefaultExecutor.java:193)
B4X:
Sub Ping(ipaddress As String)
Public shl As Shell
Dim lstParams As List: lstParams.Initialize
Try
Dim os As String = GetSystemProperty("os.name", "").ToLowerCase
If os.Contains("win") Then
lstParams.Add("-n")
Else
lstParams.Add("-c")
End If
lstParams.Add("1")
lstParams.Add(ipaddress)
shl.Initialize("shl", "ping", lstParams)
shl.WorkingDirectory = File.DirApp
shl.Run(-1)
Log("here in ping")
Catch
Log("ping error")
Log(LastException.Message)
End Try
End Sub
Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
Log("Success")
Log(StdOut)
Dim str As String=StdOut
Dim len As Int=str.Length
Dim ind As Int=str.IndexOf("Average = ")
Dim ping_time As String = str.SubString2((ind+10), len-4)
Log("takes from ping: " & str.SubString2( (ind+10), len-4) )
Else
Log("Error: " & StdErr)
End If
'ExitApplication
End Sub
when I want move to a separate class / module as:
B4X:
'Class module
Sub Class_Globals
Private fx As JFX
End Sub
Public Sub Initialize
End Sub
Sub Ping(ipaddress As String)
Public shl As Shell
Dim lstParams As List: lstParams.Initialize
Try
Dim os As String = GetSystemProperty("os.name", "").ToLowerCase
If os.Contains("win") Then
lstParams.Add("-n")
Else
lstParams.Add("-c")
End If
lstParams.Add("1")
lstParams.Add(ipaddress)
shl.Initialize("shl", "ping", lstParams)
shl.WorkingDirectory = File.DirApp
shl.Run(-1)
Log("here in ping")
Catch
Log("ping error")
Log(LastException.Message)
End Try
End Sub
Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
Log("Success")
Log(StdOut)
Dim str As String=StdOut
Dim len As Int=str.Length
Dim ind As Int=str.IndexOf("Average = ")
Dim ping_time As String = str.SubString2((ind+10), len-4)
Log("takes from ping: " & str.SubString2( (ind+10), len-4) )
Else
Log("Error: " & StdErr)
End If
'ExitApplication
End Sub
getting error of:
java.lang.NullPointerException
at anywheresoftware.b4j.objects.Shell$1.onProcessFailed(Shell.java:146)
at org.apache.commons.exec.DefaultExecutor$1.run(DefaultExecutor.java:193)