0
The following code works for when the user leaves an editText of the form blank. The code worked in Netbeans but on Androidstudio when running the APK with a blank field it shows the message that the APP has stopped working. Follows the code:
//In Netbeans
BigDecimal cota = null;
BigDecimal prazo = null;
BigDecimal reserva = null;
BigDecimal adm = null;
try {
cota = new BigDecimal(jTextField1.getText());
prazo = new BigDecimal(jTextField2.getText());
reserva = new BigDecimal(jTextField3.getText());
adm = new BigDecimal(jTextField4.getText());
} catch (NumberFormatException e) {
jLabel5.setText("Os valores não podem estar vazios!");
}
//On Android
BigDecimal cota = null;
BigDecimal prazo = null;
BigDecimal reserva = null;
BigDecimal adm = null;
BigDecimal vida = null;
try{
cota = new BigDecimal(edtCota.getText().toString());
prazo = new BigDecimal(edtPrazo.getText().toString());
reserva = new BigDecimal(edtReserva.getText().toString());
adm = new BigDecimal(edtAdm.getText().toString());
vida = new BigDecimal(edtVida.getText().toString());
}catch(NumberFormatException erro){
AlertDialog.Builder janelaVazio = new AlertDialog.Builder(Consorcio.this);
janelaVazio.setMessage("Preencha todos os campos");
janelaVazio.setNeutralButton("FECHAR", null);
janelaVazio.show();
}
I added it to see if it fixed but it didn’t change anything. It was just like the one in netbeans changing only the output of the message
– Weriky Alphazero
Does the error happen before or after dialog is presented? What error does it make?
– ramaral
The dialog does not even appear. What appears is that the app has stopped working and restarts. That’s exactly why I used Ry and Catch to try to fix this, Netbeans worked ok already on android continues
– Weriky Alphazero
The fact that some Edittext is blank is captured by Try, What may be happening is some of the attributes
edXXX
be void.– ramaral
Change Numberformatexception to Exception to analyze another type of error.
– Gustavo Bitencourt
Does not work in android Studio or bullet
– Weriky Alphazero