I have to add values to my sq lite from the list view. In my list view there are two edit texts and text view. I just want to get value from each edit text and multiply it to the corresponding text view value. when I am running the app, I need not to enter data to every edit text. due to this I am ending with a "number format exception : invalid int". From other examples I can understand that multiplication on null value may cause the error. how can I skip the null value contained edit texts from the iteration? this is my code
protected void InsertDb() {
// TODO Auto-generated method stub
DatabaseHelper databasecontroller = new DatabaseHelper(Orders.this);
List<Map<String, String>> data = null;
data = new ArrayList<Map<String, String>>();
if(list != null){
for(int i = 0; i< list.getChildCount();i++){
View vie = list.getChildAt(i);
EditText ed1= (EditText) vie.findViewById(R.id.cases);
EditText ed2 = (EditText) vie.findViewById(R.id.pcs);
String qty = ed1.getText().toString();
TextView tv = (TextView)findViewById(R.id.srp);
String imsrpv= tv.getText().toString();
float srps = Float.valueOf(imsrpv);
int qtys = Integer.valueOf(qty);
float amts = srps * qtys;
String amount = Float.toString(amts);
datanum.put("A",qty );
datanum.put("B",ed2.getText().toString() );
datanum.put("L", amount);
Log.d("value of amnt",amount);
databasecontroller.entercustdetails(datanum);
}
}
Log.v("compleated", data.toString());
}
Thanks in advance..
Check either returning value from edittext is a proper number or it is not null.if a null value is there it may give exeception of numberformat.you have to handle this. if both are correct then you can also you
float srps=0.0;
int qtys=0;
try
{
srps = Float.valueOf(imsrpv);
qtys = Integer.valueOf(qty);
}
catch (NumberFormatException e)
{
srps =//Default value you want;
qtys =//Default value you want;
}
Hope it works..