嘿,有人可以帮我解决我遇到的错误。我正在从我的档案中拆开线路并检查它们是低中还是高。如果字符串为空,我想读取文件中的下一行。我认为错误是当我将刺痛解析为双倍时。这是我的代码,任何帮助都会得到帮助!首先这是我的错误
Exception in thread "main" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
at java.lang.Double.parseDouble(Unknown Source)
at BSCQueryManager.displayBar(BSCQueryManager.java:431)
at BSCQueryManager.main(BSCQueryManager.java:57)
这是我的代码
String vMag;
String data;
double v;
int highCount = 0;
int medCount = 0;
int lowCount = 0;
// read file
File inFile = new File("bsc.dat");
Scanner starFile = new Scanner(inFile);
// while there is a vmag
while(starFile.hasNext()){
// read next line
data = starFile.nextLine();
data = data.substring(102, 107);
data.trim();
// if no vmag read next line
if(data.trim()!= ""){
v = Double.parseDouble(data);
// if vmag is > 6.0 add to countHigh
if (v > 6){
highCount++;
}
// if vmag is 5-6 add to countMed
if (v >= 5 && v <= 6){
medCount++;
}
// if vmag is < 5 add to countLow
if (v < 5){
lowCount++;
}
// end if
}
// end while
}
// display label
System.out.println(label);
System.out.println(highCount);
System.out.println(lowCount);
System.out.println(medCount);