If + try - catch in method not working properly

ems1

New Member
I'm working on an SQLite based app. Everything is working fine, except my if-else statements in my method. The saving and stuff works, just the checking is giving me a pretty high blood pressure. I'm hoping one of you is much smarter than i am and finds the probably obvious mistake i made:\[code\]public void save() { // get length of EditText int dateLength, mileageLength, amountLength, lpriceLength, tpriceLength; dateLength = date_widget.getText().length(); mileageLength = mileage_widget.getText().length(); amountLength = amount_widget.getText().length(); lpriceLength = price_widget.getText().length(); tpriceLength = totalPrice_widget.getText().length(); // Start save method if EditTexts are not empty. if (dateLength > 0 || mileageLength > 0 || amountLength > 0 || lpriceLength > 0 || tpriceLength > 0) { // Get the value of each EditText and write it into the // String/doubles String date = date_widget.getText().toString(); double mileage = Double .valueOf(mileage_widget.getText().toString()); double amount = Double.valueOf(amount_widget.getText().toString()); double lprice = Double.valueOf(price_widget.getText().toString()); double tprice = Double.valueOf(totalPrice_widget.getText() .toString()); // Check if mileage is increasing, else cancel and show toast int checkMileage = Integer.parseInt(db .getSearchResult("mileage", 0)); if (checkMileage < mileage) { try { // if (id == null) { db.insert(date, mileage, amount, lprice, tprice); Toast.makeText(this, R.string.action_input_saved, Toast.LENGTH_SHORT).show(); finish(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(this, "ERROR " + e, Toast.LENGTH_LONG) .show(); } } else { Toast.makeText( this, "Your current mileage must be more than the last saved mileage", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(this, "finish your input", Toast.LENGTH_LONG).show(); } }\[/code\]
 
Top