String 将字符串转换为双get错误
我通过这段代码在java中捕获外部.exe文件的输出值String 将字符串转换为双get错误,string,double,converter,String,Double,Converter,我通过这段代码在java中捕获外部.exe文件的输出值 Process p = Runtime.getRuntime().exec("filepath\\myexefile.exe 5.53 46.46"); // 5.53 and 46.46 are two input orguments of exe file BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
Process p = Runtime.getRuntime().exec("filepath\\myexefile.exe 5.53 46.46"); // 5.53 and 46.46 are two input orguments of exe file
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String s;
while ((s = stdInput.readLine()) != null) {
System.out.println(s); }
Double d = Double.valueOf(s);
System.out.println(d);
}
代码运行正常,并按预期显示输出53.4429
Exception in thread "main" java.lang.NullPointerException
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1008)
at java.lang.Double.valueOf(Double.java:504)
知道为什么字符串没有转换成双精度吗?提前感谢,因为循环一直运行到
s
为null,然后您要传递s
——现在是null
,请记住——到Double\valueOf(String)
要解决此问题,请在循环内解析s
。
String s;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
Double d = Double.valueOf(s);
System.out.println(d);
}
@这在这里真的没有帮助。OP向我们展示了失败的代码,以及由此产生的堆栈跟踪。我指的是他试图找出的异常。