2 回答
TA贡献1802条经验 获得超6个赞
这意味着您尝试将空String强制转换为浮点数。
也许在这里: Float price = Float.parseFloat(priceString);
因此改写为:
private void saveItemCheck() {
String nameString = mNameEditText.getText().toString().trim();
String priceString = mPriceEditText.getText().toString().trim();
String quantityString = mQuantityEditText.getText().toString().trim();
String supplierString = mSupplierEditText.getText().toString().trim();
String supplierNumberString = mSupplierNumberEditText.getText().toString().trim();
if (mCurrentInventoryUri == null &&
TextUtils.isEmpty(nameString) && TextUtils.isEmpty(priceString) &&
TextUtils.isEmpty(quantityString) && TextUtils.isEmpty(supplierString) &&
TextUtils.isEmpty(supplierNumberString)) {
return;
}
if (TextUtils.isEmpty(nameString) || TextUtils.isEmpty(priceString)
|| TextUtils.isEmpty(quantityString) || TextUtils.isEmpty(supplierString)
|| TextUtils.isEmpty(supplierNumberString)) {
Toast.makeText(this, "Please fill all the starred fields to save the product",
Toast.LENGTH_LONG).show();
} else {
Float price = Float.parseFloat(priceString);
int quantity = Integer.parseInt(quantityString);
saveItem(nameString, price, quantity, supplierString, supplierNumberString);
}
}
TA贡献1757条经验 获得超7个赞
String priceString = mPriceEditText.getText().toString().trim();
if(!TextUtils.isEmpty(priceString))
Float price = Float.parseFloat(priceString);
String quantityString = mQuantityEditText.getText().toString().trim();
if(!TextUtils.isEmpty(quantityString))
int quantity = Integer.parseInt(quantityString);
您必须检查edittext是否为空,而不是转换为float的int之后
添加回答
举报