Getting a NumberFormatException from a numerical EditText field

前端 未结 7 828
长情又很酷
长情又很酷 2021-01-25 12:16

I\'m trying to create a for-loop to add views to a layout. The for-loop is working fine (I tried it with initialized variables) but I need to get an in

相关标签:
7条回答
  • 2021-01-25 13:13

    In order to prevent an int from getting a "" value, which is what happens when there's a second click in an empty EditText field, you can throw this line in your java code:

    int i;
    String change = numSensors.getText().toString();
    if(!(change.equals("")))
    {
      i = Integer.parseInt(change);
    }
    
    0 讨论(0)
提交回复
热议问题