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

前端 未结 5 1970
南笙
南笙 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 09:14

    put a check before doing Integer.parseInt like

    final int a = (height == null || height.trim().equal("") ? 0 : Integer.parseInt(height));
    

    Also you need to add this code for getting the height value from edittext inside onclick listener as when in OnCreate control will not have any value apart you set some default value in layout.xml as it is just created

提交回复
热议问题