whats wrong?(NumberFormatException: null)

前端 未结 4 1096
轮回少年
轮回少年 2020-12-18 09:37
    import java.io.*;
    class AccountInfo {

    private String lastName;
    private String firstName;
    private int age;
    private float accountBalance;
             


        
4条回答
  •  隐瞒了意图╮
    2020-12-18 10:26

    1. I think the value returned from br.readLine() is null.

    2. So it can NOT be converted from String to Integer.

    3. Thats the reason you are getting NumberFormatException

    4. To handle this, Wrap that code into try/catch block.

     try{
    
            age = Integer.parseInt(br.readLine());
    
    
      }catch(NumberFormatException ex){
    
    
            System.out.println("Error occured with during conversion");
     }
    

提交回复
热议问题