[Solved] Toast Error message, but The Application is still running the code [closed]


Maybe you need like this:

public void doSomeWork() {

   String usiaTahun = tahunUsia.getText().toString();

   // check value is empty
   if (!usiaTahun.isEmpty()) {

       // parse string to integer
       int tahunAngka = Integer.parseInt(usiaTahun);

       // check value is in between 0 to 5
       if (tahunAngka < 0 || tahunAngka > 5) {

           // error message
           Toast.makeText(MainActivity.this, "Tahun Yang Anda Masukkan Tidak Sesuai", Toast.LENGTH_SHORT).show();

        } else {

           // do your code here if number is in between 0 to 5

        }

   } else {

       // error message
       Toast.makeText(MainActivity.this, "Please enter a value", Toast.LENGTH_SHORT).show();

   }

}

Call this doSomeWork() in you button’s onClick() method.

8

solved Toast Error message, but The Application is still running the code [closed]