java.lang.NumberFormatException: For input string: "10"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:441)
相关代码段:
public static class NodeWritable implements Writable {
public double msg;
public double rank;
public String others;
public NodeWritable(double msg, double rank, String others) {
this.msg = msg;
this.rank = rank;
this.others = others;
}
public NodeWritable() {
this.msg = 0.0;
this.rank = 0.0;
this.others = "";
}
@Override
public void write(DataOutput out) throws IOException {
out.writeDouble(msg);
out.writeDouble(rank);
out.writeChars(others + "\n");
}
@Override
public void readFields(DataInput in) throws IOException {
msg = in.readDouble();
rank = in.readDouble();
others = in.readLine();
}
@Override
public String toString() {
return "" + rank;
}
}
ArrayList<Long> incoming_vids = new ArrayList<Long>();
for (NodeWritable msg : messages) {
String in_vid = msg.others.trim();
incoming_vids.add(Long.parseLong(in_vid));
}
怎么会这样我已经与Google进行了一些研究。有时
NumberFormatException
似乎是由大数字引起的。但我只是无法为我的案件找到可能的解释。 最佳答案
您可以在字符串in_vid上循环并使用此命令检查是否除数字以外的任何字符
for(int i=0;i<in_vid.length();i++) {
char ch = in_vid.charAt(i);
if( Character.isDigit(ch)) {
// do something
}
}
如果它不是数字,则可以在循环中将其消除,并仅传递具有数字的字符串。
关于java - ParseLong引发NumberFormatException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20138512/