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 <
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.
}
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!!!}
I think, you should have to add this to your edit text
editText.setHint("0");
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.....
try
if(monthlyTest == null || monthlyTest.trim().equals("")){
You could also use
if(monthlyTest == null || monthlyTest.trim().isEmpty()){