B4J Question NullPointerException when killing a process

wl

Well-Known Member
Licensed User
Longtime User
Hi,

I launch an external process (php server) using jShell and after a while I want to kill this process (demo app):

B4X:
Sub AppStart (Args() As String)
    shl.Initialize("shl", "c:/php/php.exe", Array As String ("-S", "0.0.0.0:8000"))
    
    tmr.Initialize("tmr", 10000)
    tmr.Enabled = True
    
    StartMessageLoop
End Sub

Sub tmr_Tick
    shl.KillProcess
End Sub

When I try to kill the process I get a NullPointerException:

at anywheresoftware.b4j.objects.Shell.KillProcess(Shell.java:146)
 

wl

Well-Known Member
Licensed User
Longtime User
I extended the code but receive the same error.

Note that it is a console application.

B4X:
Sub AppStart (Args() As String)
    shl.Initialize("shl", "c:/php/php.exe", Array As String ("-S", "0.0.0.0:8000"))  
    shl.Run(-1)
    tmr.Initialize("tmr", 10000)
    tmr.Enabled = True
   
    StartMessageLoop
End Sub


Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log (Success)  
End Sub

Sub tmr_Tick
    shl.KillProcess
End Sub

true
main._appstart (java line: 60)
java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4a.objects.Timer$TickTack$1.run(Timer.java:118)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
at b4j.example.main._appstart(main.java:60)
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:91)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:28)
Caused by: java.lang.NullPointerException
at anywheresoftware.b4j.objects.Shell.KillProcess(Shell.java:146)
at b4j.example.main._tmr_tick(main.java:99)
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:91)
... 12 more
main.main (java line: 28)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.main(main.java:28)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:120)
at anywheresoftware.b4a.objects.Timer$TickTack$1.run(Timer.java:118)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:153)
at b4j.example.main._appstart(main.java:60)
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:91)
... 2 more
Caused by: java.lang.NullPointerException
at anywheresoftware.b4j.objects.Shell.KillProcess(Shell.java:146)
at b4j.example.main._tmr_tick(main.java:99)
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:91)
... 12 more
 
Upvote 0

Daestrum

Well-Known Member
Licensed User
Longtime User
Are you sure the process has actually been started? Does it show up in task manager ?
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Thanks all. My mistake ... I ran the shell inside a server application that was also listening on port 8000 (the same port I asked the php server to listen to). I did not include this code as it seemed not relevant :-( Sorry

so in fact the PHP server was never started (though I did not notice this and I thought it was) ad so killing it resulted in the error.

Then in fact in a next step there was again the nullpointer exception: but in this case it was indeed cause the second time the timer ticked (as Erel indicated)
 
Upvote 0
Top