I am trying to have an error message when the use enters a number for an item that cannot be deleted in the database. I have gotten it so the user can delete an item from the database and I think used the try catch to avoid a run time error if the number does not exist. What I am trying to do is have a toast pop up when the user enter an invalid number. I have already looked at other similar postings on stack and have not have any luck. Here is my code. If you need me to post more code let me know.
public void onClick(DialogInterface dialog, int which) {
try {
String id=idNum.getText().toString();
long primaryId=Long.parseLong(id);
info.open();
info.deleteInspection(primaryId);
info.close();
dbInfo();
} catch(Exception e) {
Toast.makeText(getApplicationContext(), "Number not found", Toast.LENGTH_SHORT).show();
}
}
You could make your
deleteInspection()method return a boolean value, telling wether or not a given id was deleted. Then check for it in your onClick method: