java.lang.NumberFormatException: Invalid int: “” : Error

前端 未结 5 1989
南笙
南笙 2021-01-21 08:22

I am doing some calculation but unable to parse a string into int or even in float.I searched for solution and i read it somewhere there must be a empty string but i checked my

5条回答
  •  太阳男子
    2021-01-21 08:55

    You are trying to parse an empty String ( "" ) to a numerical value, but "" is not a numerical value.

    Make sure you set it to required, or check for emptiness before trying to parse it.

    final int a = !height.equals("")?Integer.parseInt(height) : 0;
    

    for instance.

    EDIT:

    If you have added spaces, so it would be " ";

    height = height.trim();
    final int a = !height.equals("")?Integer.parseInt(height) : 0;
    

    should do the trick.

提交回复
热议问题