jeudi 5 juillet 2018

String is correct length but still getting error

Programming in Android/Java. I get both the log error message and the popup alert when string length is both correct or incorrect. I have attempted to use (txtVin.length() ==17) but that isn't working either. Any and all help would be appreciated.

public void checkVIN() {
    if (txtVin.length() != 17) {
        Log.d("VIN", "Invalid VIN Length");
        AlertDialog.Builder alertInvalidLength = new AlertDialog.Builder(this);
        alertInvalidLength.setMessage("VIN is too short!");
        alertInvalidLength.setTitle("Warning:");
        alertInvalidLength.setPositiveButton("OK", null);
        alertInvalidLength.setCancelable(true);
        alertInvalidLength.create().show();
    } else {
        // Validate checksum.
        char weightDigit = getWeightDigit();
        if (txtVin.charAt(8) != weightDigit) {
            Log.d("VIN", "Invalid VIN!");
            AlertDialog.Builder alertInvalidVIN = new AlertDialog.Builder(this);
            alertInvalidVIN.setMessage("VIN is invalid!");
            alertInvalidVIN.setTitle("Warning:");
            alertInvalidVIN.setPositiveButton("OK", null);
            alertInvalidVIN.setCancelable(true);
            alertInvalidVIN.create().show();

        }
    }
}

Aucun commentaire:

Enregistrer un commentaire