B
Binaebi A.
I'm currently writing a java program that interfaces with a Perl
script through a Linux command shell. I am able to interact with the
script, but with each action I get a Null Exception Error which does
not prevent the program from working. How is it possible that an error
can be thrown and yet not stop the program from working?
I am testing to make sure the process is completed before the program
exits, and I'm wondering if maybe the exit value is not returning as
it should. I know the error is somewhere at the end of my code,
because everything in the method executes perfectly. I get correct
return values, but when I try to send the exit value to the screen, no
value shows up. I have looked online at other examples of code, and
mine seems to match theirs...so I'm wondering how it's possible that
my code has decided to ignore the exit value and (I think) thereby
cause a null pointer exception.
I have included my code in the hopes someone will have an idea how to
help me correct this odd error.
*******************************************************************************
ArrayList getIdFromUser () {
ArrayList pbsIdArray = new ArrayList();
try {
//send command line to new shell
Process proc = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
BufferedReader error = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
//read input, test substring for pbs id
String line;
while(!(line = in.readLine()).equals(null)) {
//System.out.println(line);
if (test values) {
//if true, nothing should happen
}
else {
//if false, add pbs to array list
pbsId = line;
pbsIdArray.add(pbsId);
}
}
//read error results
String eLine;
while(!(eLine = error.readLine()).equals(null))
pbsIdArray.add(eLine);
//wait for the process to end, then close process
try{ proc.waitFor(); }
catch(InterruptedException ie) {
pbsIdArray.add("ERROR: Process interrupted: " + ie.toString());
}
System.err.println("Exit: " + proc.exitValue());
//close streams
in.close();
error.close();
} catch (IOException e) {
pbsIdArray.add("ERROR: File not found.");
}
catch (NullPointerException n) {
pbsIdArray.add("ERROR: Null Pointer Exception.");
/*this is the error I get even though it doesn't throw me
from the method before its internal workings are
complete*/
}
return pbsIdArray;
}
script through a Linux command shell. I am able to interact with the
script, but with each action I get a Null Exception Error which does
not prevent the program from working. How is it possible that an error
can be thrown and yet not stop the program from working?
I am testing to make sure the process is completed before the program
exits, and I'm wondering if maybe the exit value is not returning as
it should. I know the error is somewhere at the end of my code,
because everything in the method executes perfectly. I get correct
return values, but when I try to send the exit value to the screen, no
value shows up. I have looked online at other examples of code, and
mine seems to match theirs...so I'm wondering how it's possible that
my code has decided to ignore the exit value and (I think) thereby
cause a null pointer exception.
I have included my code in the hopes someone will have an idea how to
help me correct this odd error.
*******************************************************************************
ArrayList getIdFromUser () {
ArrayList pbsIdArray = new ArrayList();
try {
//send command line to new shell
Process proc = Runtime.getRuntime().exec(cmd);
BufferedReader in = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
BufferedReader error = new BufferedReader(new
InputStreamReader(proc.getErrorStream()));
//read input, test substring for pbs id
String line;
while(!(line = in.readLine()).equals(null)) {
//System.out.println(line);
if (test values) {
//if true, nothing should happen
}
else {
//if false, add pbs to array list
pbsId = line;
pbsIdArray.add(pbsId);
}
}
//read error results
String eLine;
while(!(eLine = error.readLine()).equals(null))
pbsIdArray.add(eLine);
//wait for the process to end, then close process
try{ proc.waitFor(); }
catch(InterruptedException ie) {
pbsIdArray.add("ERROR: Process interrupted: " + ie.toString());
}
System.err.println("Exit: " + proc.exitValue());
//close streams
in.close();
error.close();
} catch (IOException e) {
pbsIdArray.add("ERROR: File not found.");
}
catch (NullPointerException n) {
pbsIdArray.add("ERROR: Null Pointer Exception.");
/*this is the error I get even though it doesn't throw me
from the method before its internal workings are
complete*/
}
return pbsIdArray;
}