【问题标题】:FileReader runtime errorFileReader 运行时错误
【发布时间】:2016-08-12 18:56:28
【问题描述】:

我试图解决问题,但仍然无法为错误提供资金......

 class ReadWriteFile extends Patron{
 static void readFile (Patron p[]){
    try{
        File file = new File("patron.txt");
        int cnt=0;

        FileReader fr = new FileReader (file);
        Scanner scan = new Scanner(fr);
        String temp = scan.nextLine();
            while(temp!=null){
                System.out.print(temp);
                String tempPatron[] = temp.split("|");
                String id_codes = Integer.parseInt(tempPatron[0].trim());
                String names = tempPatron[1];
                String S_addresss = tempPatron[2];
                int post_codes = Integer.parseInt(tempPatron[3].trim());
                double overdue_balances = Double.parseDouble(tempPatron[4]);
                String passwords =tempPatron[5];
                p[cnt] = new Patron(id_codes, names, S_addresss, post_codes, overdue_balances, passwords);
            //  System.out.print(p[cnt]);
                cnt++;
                temp=scan.nextLine();                   
            }
    }   catch (Exception ex){
        //ex.printStackTrace();
    }
}

}

这个错误有什么问题..当我在文本内部扫描时,第一个值会出错....

 ? a d | A u n   Z h i   G i e | J a l a n   K e p o n g | 5 2 1 0 0 | 1 . 0    0 | C 1 2 3 java.lang.NumberFormatException: For input string: "a"
at         java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  at java.lang.Integer.parseInt(Integer.java:580)
  at java.lang.Integer.parseInt(Integer.java:615)
  at ReadWriteFile.readFile(patron.java:50)
  at Main.main(Testingprogram.java:6)

【问题讨论】:

    标签: java text-files filereader


    【解决方案1】:

    您正在对不代表整数的字符串调用Integer.parseInt()(patron.jave 的第 50 行)。错误消息说字符串是“a”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多