每当我在不输入价格的情况下提交详细信息时,它都会显示错误,不幸的是您的项目已停止工作,例如价格在数据库中具有整数类型。除了价格,所有其他领域都工作正常。
任何人请帮我解决........
<EditText android:id="@+id/txtprice"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:ems="10"
android:numeric="decimal|integer"/>
.java
private void adddetails() {
// TODO Auto-generated method stub
String catname=spinner1.getSelectedItem().toString();
String member=txtname.getText().toString();
int price=Integer.parseInt(txtprice.getText().toString());
String price1=txtprice.getText().toString();
String desc=txtdesc.getText().toString();
String date=txtdate.getText().toString();
validation();
if(txtname.getText().toString().length() == 0||txtdesc.getText().toString().length() == 0|| txtprice.getText().toString().length() == 0||price < 0 || price1==""){
Toast.makeText(getApplicationContext(), "Enter all details",
Toast.LENGTH_SHORT).show();
}
else{
long id = dbAdapter.add(catname, member, price, desc, date);
if (id > 0) {
Toast.makeText(getApplicationContext(), "Details has addded successfully",
Toast.LENGTH_SHORT).show();
txtname.setText("");
txtprice.setText("");
txtdesc.setText("");
txtdate.setText("");
//categoryList.set(0, "");
System.out.println(" categoryList.get(0) ****** " + categoryList.get(0));
categoryList.set(0, categoryList.get(0));
dataAdapter.notifyDataSetChanged();
} else {
Toast.makeText(getApplicationContext(), "Failed to add new details",
Toast.LENGTH_SHORT).show();
}
}
}
private void validation() {
// TODO Auto-generated method stub
int price=Integer.parseInt(txtprice.getText().toString());
String price1=txtprice.getText().toString();
if( txtname.getText().toString().length() == 0 )
txtname.setError( "Member name is required!" );
if( txtdesc.getText().toString().length() == 0 )
txtdesc.setError( "Description is requied!" );
if( txtdate.getText().toString().length() == 0 )
txtdate.setError( "select date is required!" );
*if( txtprice.getText().toString().length() == 0 || price1.matches("^[0-9]$")==false )
txtprice.setError( "Expense amount is requied!" );*
if( price < 0 || price1==""){
Toast.makeText(getApplicationContext(), "price field ",
Toast.LENGTH_SHORT).show();
}
}