java - For input string: "" when textfields are filled out -


i writing program in java got textfields , button.

i java.lang.numberformatexception: input string: "" though have filled out textfields when running program.

my code looks this:

button.addactionlistener(new actionlistener() {     @override     public void actionperformed(actionevent e) {         method();     } }             );     public void method() {      try {          string string1 = textfield1.gettext();         string string2 = textfield2.gettext();         string string3 = textfield3.gettext();         if ( string1.length() == 0 || string2.length() == 0 || string3.length() == 0) {              system.out.println("fill in required text fields");             return;         }          int number = integer.parseint(textfield3.gettext());         //do     }     catch ( numberformatexception e ) {          system.out.println("wrong format");     } } 

edit:

see more code here

i have tested program little bit , have problem text field, because of creation of panel , switching 1 active.

in constructor call something() method creates jtextfield. when button clicked call again something() , new jtextfield generated add panel.

so have 2 jtextfields on gui @ exact same position reference 1 of them (the last 1 created).

when click button call method(). hidden textfield asked text (this how works on pc) , empty because can write 1 see.

an easy fix change method actionperformed:

@override public void actionperformed( actionevent e ) {     if ( e.getsource() == button1 ) {         present = something;         button1.setvisible(false);         //something();         visiblepanel();         previous = something;     }  } 

so avoid new creation of jtextfield visiblepanel() ensures textfield , second button shown.

after change can type in "sadda" press button , see output "numberformatexception". when type in number see nothing formatting works.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -