jeudi 19 septembre 2019

Android, if ( EditText == null ) five me errors

I have some issue with a validation that use if statement. I need to have all EditText obligatory but with one in particular i have different issues and i cant figured out how to solve it. Here the code:

String inputTurno = etTurno.getText().toString().trim();
String inputCodice = tvCodice3.getText().toString().trim();
String progressivoString = etProgressivo.getText().toString().trim();

int inputProgressivo = Integer.parseInt(progressivoString);



if ( progressivoString.isEmpty()){
                Toast.makeText(activity, "Perfavore riempire progressivo", Toast.LENGTH_SHORT).show();
            } else if (inputTurno.isEmpty() || inputCodice.equals("")){
                Toast.makeText(activity, "Perfavore Inserisci numero valido", Toast.LENGTH_SHORT).show();
            } else {
                 Intent stampaIt = new Intent(InizioTurno.this, TextActivity.class);
                startActivity(stampaIt);
            }

When i start the ifstatemnt on if (inputTurno.isEmpty() || inputCodice.equals("")) all work fine but when i have to check the progressivoString.isEmpty() five me every time this error:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.test.printertestdemov1, PID: 22225
java.lang.NumberFormatException: For input string: ""
    at java.lang.Integer.parseInt(Integer.java:533)
    at java.lang.Integer.parseInt(Integer.java:556)
    at com.sunmi.printerhelper.activity.InizioTurno$2.onClick(InizioTurno.java:70)

Aucun commentaire:

Enregistrer un commentaire