A swingworker does not work

87 views Asked by At

In my application I have two different swingworkers (they do two different jobs). The first one works perfectly, while the latter does not.

What I can do to fix it?

class worker extends SwingWorker<Boolean, String> {     
    @Override
     protected Boolean doInBackground() throws Exception {
        getstub().registration(name.getText(), surname.getText());
      return true;
     }

     protected void done() {
      boolean status;
      try {
       status = get();
       regstatus.setText("registration status: " + status);
      } catch (InterruptedException e) {
      } catch (ExecutionException e) {
      }
     }
}


class worker1 extends SwingWorker<Boolean, String> {        
    @Override
     protected Boolean doInBackground() throws Exception {
        int i = Integer.parseInt(id.getText());
        double r = Double.parseDouble(range.getText());
        double la = Double.parseDouble(lat.getText());
        Coordinate lat = new DegreeCoordinate(la);
        double lo = Double.parseDouble(lon.getText());
        Coordinate lon = new DegreeCoordinate(lo);
        System.out.println("id: "+i+" lat: "+la+ " lon: "+lo+" type: "+type.getText()+ " range: "+r);
        getstub().request(i, lat ,lon ,type.getText(), r);          
        return true;
     }

     protected void done() {

      boolean status;
      try {
       status = get();
       reqstatus.setText("request status: " + status);
      } catch (InterruptedException e) {
      } catch (ExecutionException e) {
      }
     }
}

and two jbuttons that start the worker

 private JButton register = new JButton("Register");
 register.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent arg0) {
              new worker().execute();
           }
          });

private JButton search = new JButton("Search now");
search.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent arg0) {
                   reqstatus.setText("I'm searching...");
                   new worker1().execute();                    
               }
              });
1

There are 1 answers

9
Nick Volynkin On BEST ANSWER

The problem in large scope

Looks like you're using ninja-exception-logging (the invisible one):

  } catch (InterruptedException e) {
  } catch (ExecutionException e) {
  }

Do some real logging there and you will most probably see the problem. At least use System.out.println(); a better choice is log4j.

  } catch (InterruptedException e) {
      //a thread exception, quite unlikely to happen
      System.out.println(e);
  } catch (ExecutionException e) {
      System.out.println(e);
  }

The particular mistake

With logging enabled, a NumberFormatException, wrapped in the ExecutionException was found.