MyException - 我的异常网
当前位置:我的异常网» Eclipse » Exception in thread "main" java.lang.N

Exception in thread "main" java.lang.NumberFormatException:

www.MyException.Cn  网友分享于:2013-11-11  浏览:486次
从文本文件中读出点的坐标
public class w {

public static void main(String args[]) throws NumberFormatException,IOException {

BufferedReader br = new BufferedReader(new FileReader("D://1.txt"));
String str = "";
while ((str = br.readLine()) != null && str != "") {
String[] p = str.split(",");
int x = Integer.parseInt(p[0]);
int y = Integer.parseInt(p[1]);
System.out.println("<"+x+","+y+">");
}
}
}
这段程序执行后有错误:
Exception in thread "main" java.lang.NumberFormatException: For input string: "0,1"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at w.main(w.java:13)
怎么改?


------解决方案--------------------
Java code

BufferedReader br = new BufferedReader(new FileReader("D://1.txt"));
        String str = "";
        while ((str = br.readLine()) != null && str != "") {
            String[] p = str.split(",");
            int x = Integer.parseInt(p[0]);
            int y = Integer.parseInt(p[1]);
            System.out.println("<" + x + "," + y + ">");

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有