Java CRUD MVC, Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "" [closed]

0

I have a normal CRUD, at the time of doing the search part I have a small problem, I want to search the bd with any data right? that is, if you type the name, then the rest of the data comes out, if you search by phone, the rest of the data is the same, all of which I have as String, the one of the cedula that is commented if I have it for integer, then ... How I ask you to search for it? to put it normal marks me of an error

I do a parseInt and either, that is, the ID card works normally, but now all the Strings do not work for me

    
asked by Julian David Ortiz Idrobo 11.12.2018 в 16:57
source

2 answers

0

In this case I see that you want to use any of the form fields for your search, the problem is that when you press the search button the Certificate String is empty and therefore can not be converted to whole, I would use something like that.

First we check that the Field is loaded and then convert to Integer.

try{


    if(!frm.txtCedula.getText().isEmpty()){
       objeto.setCedula(Integer.parseInt(frm.txtCedula.getText())); 
    }


    }catch(Exception ex){
        System.err.println("Error:"+ex.getMessage());
    }

We use try catch for anything, then what we do is ask if txtCedula is empty and if it is not, then do not do anything.

    
answered by 11.12.2018 / 17:43
source
0

That exception corresponds to that you are putting an erroneous data, eg. in a field of type int you are putting a data type String or vicecersa!.

    
answered by 11.12.2018 в 17:15