Link to home
Start Free TrialLog in
Avatar of Tscott84
Tscott84

asked on

Trying to pinpoint why I keep getting this error while executing client Server application Exception in thread "Thread-0" java.lang.NullPointerException

I get this error Exception in thread "Thread-0" java.lang.NullPointerException
        at java.lang.Runtime.exec(Runtime.java:424)
        at java.lang.Runtime.exec(Runtime.java:328)
        at ClientProcess.execProcess(P1Server.java:98)
        at ClientProcess.run(P1Server.java:69)
        at java.lang.Thread.run(Thread.java:619)
Evertime my server sends my client a message/reply......I am trying to pinpoint
the problem and am lost....I would greatly appreciated if someone could give some insight......Thanks
Avatar of Mick Barry
Mick Barry
Flag of Australia image

>         at ClientProcess.execProcess(P1Server.java:98)

check line 98 of P1Server
check what parameters you are passing to exec.
Avatar of Tscott84
Tscott84

ASKER

ok Im going to check it out thanks for responding so fast
at line 98 I am beginning my try catch......I still dont see any thing that sticks out to me
private void execProcess(String aCommand)
    {
        
        try
        {
            
            Runtime runtime =Runtime.getRuntime();
            Process p = runtime.exec(aCommand);
            BufferedReader in = new BufferedReader
                               (new InputStreamReader(p.getInputStream()));  
                    String line = null;  
                    while ((line = in.readLine()) != null) 
                    {
                        
                        toClient.println(line); 
                    
                    }//end while
        
        }
        catch (IOException e) 
        {
            
            e.printStackTrace();
        
        }//try-catch
 
    }//end execProcess()
 
}//end Client Process         

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok im gonna check it out
ok echoe printed my clientReq/aCommand twice

once in my run() and once in my execProcess

and this my result so yeah it is null but I am getting the results on my client Side

uptime
uptime
null
null
 02:49:17 up 73 days, 11:28,  1 user,  load average: 0.07, 0.06, 0.07


Exception in thread "Thread-1" java.lang.NullPointerException
        at java.lang.Runtime.exec(Runtime.java:424)
        at java.lang.Runtime.exec(Runtime.java:328)
        at ClientProcess.execProcess(P1Server.java:100)
        at ClientProcess.run(P1Server.java:70)
        at java.lang.Thread.run(Thread.java:619)

Open in new window

hey thanks I think I got it  took the while loop out it was like looping and the clientReq
was continously getting read by the execProcess even after it was read ...thats why
my client was getting the reply but the second time it was read my aCommand was null
so............THANKS ALOT