Get integer value from edittext

前端 未结 3 341

When I try to run the code below, my program has stops. I want this code to get the value from edittext but it´s not working as I expected it. What am I doing wrong

3条回答
  •  借酒劲吻你
    2021-01-25 00:59

    - Please check the value of EditText, is it a valid integer value or not.

    Try out this code:

    int i = 0;
    
    try{
    
      i = Integer.parseInt(from.getText().toString());
    
    }catch(NumberFormatException ex){
    
      System.out.println("Value at TextView is not a valid integer");
    
    }
    

提交回复
热议问题