joptionpane - Error in Java application -


code in action listener of save button:

i= integer.parseint(txt_userid.gettext()); s= txt_pass.gettext(); n = txt_name.gettext(); try {     if(txt_userid.gettext().isempty() || (txt_pass.gettext().isempty() || txt_name.gettext().isempty())))     {         joptionpane.showmessagedialog(null, "incomplete input!");     }     else{         rs.movetoinsertrow();         rs.updateint("userid", i);         rs.updateint("password", s);         rs.updateint("name", n);         rs.insertrow():             joptionpane.showmessagedialog(useraccountform.this, "record saved"):         } } catch(sqlexception err) {     system.out.println(err.get message()); } 

my problem when 1 or 2 text field left empty information typed must not save , must pop message dialog "incomplete input". works fine txt_pass , txt_name both string, whenever left text field (txt_userid) empty gives me error. why that?

i have had same issue, can avoid checking first whether null or not. change portion:

if(txt_userid.gettext().isempty() || (txt_pass.gettext().isempty() || txt_name.gettext().isempty()))) {     joptionpane.showmessagedialog(null, "incomplete input!"); } 

to:

if(txt_userid.gettext()==null || txt_pass.gettext()==null || txt_name.gettext()==null || txt_userid.gettext().isempty() || txt_pass.gettext().isempty() || txt_name.gettext().isempty()) {     joptionpane.showmessagedialog(null, "incomplete input!"); } 

in addition, add try-catch, before existing try-catch.

change:

i= integer.parseint(txt_userid.gettext()); s= txt_pass.gettext(); n = txt_name.gettext(); 

to:

try {     i= integer.parseint(txt_userid.gettext());     s= txt_pass.gettext();     n = txt_name.gettext(); } catch(exception ex) {     ex.printstacktrace(); // @ least right } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -