Skip to content Skip to sidebar Skip to footer

Edit Text Shows Exception Invalid Int ""

I have already tried setting the EditText default value to be zero but when it comes to editing and erase as '' ( empty space , no more wordings _ in the Edit Text field It shows

Solution 1:

In the aboue code you have used like converting String to Integer in that case you will not convert ""(Empty String) to Integer

Integer.parseInt(monthlyTest);  // Here monthyTest value is ""

Please make sure the string is not empty befor conversion.

Check the length of the String is should be greater than 0.

if(monthlyTest.length()>0)

Thanks.....

Solution 2:

try

if(monthlyTest == null || monthlyTest.trim().equals("")){

You could also use

if(monthlyTest == null || monthlyTest.trim().isEmpty()){

Solution 3:

Surround the offending lines with a try/catch block.

try {
    Log.d("Month" , monthlyTest);
    Log.d("freeMonths" , freeMonths);                               
    monthlyFeeforChannel =  Integer.parseInt(monthlyTest);                                      
    MonthlyFee.add(monthlyFeeforChannel);
    FreePeriod.add(freeMonths);
}
catch (NumberFormatException nfe) {
    nfe.printStackTrace();
    // Alert the user/log the error, etc.
}

Solution 4:

I think, you should have to add this to your edit text

editText.setHint("0");

Solution 5:

If the input type is set to number you cannot test for "null" so the best solution is to test if length is zero, this way:

if(number.length() == 0) {EditText is empty!!!}

Post a Comment for "Edit Text Shows Exception Invalid Int """