Search code examples
javaswingswingworker

SwingWorker : illegal start of type


it is a piece of code that caused my problem :

   SwingWorker <Vector,void> sw=new SwingWorker <Vector,void>(){

     @Override
        protected Vector doInBackground() throws Exception {

             TvaJpaController tjc =new TvaJpaController(emf);
           Vector  l_tva=null;

          try{
         l_tva= (Vector) tjc.findTvaEntities();

             }
        catch(javax.persistence.PersistenceException e)
             {

             javax.swing.JOptionPane.showMessageDialog(null,"please check your internet connecting"); 

             } 
       return l_tva;
     }

     @Override
        protected void done() {
     Vector   l_tva=null;
            try {
                  l_tva=get();
            } catch (InterruptedException ex) {
                Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ExecutionException ex) {
                Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
            }

         int n =  l_tva.size();
          for(int i=0;i<n;i++){
       Tva tva =(Tva)l_tva.elementAt(i);
   tva_article.addItem(tva.getIdtva());

   }

     }
   };

    sw.execute(); 

this line :

SwingWorker <Vector,void> sw=new SwingWorker <Vector,void>()

gives an error :illegal start of type... I think my problem was due to "vector",but I do not know how to solve.. Any Helps ?


Solution

  • No, the problem is the use of void, which isn't a valid type argument. You can use SwingWorker<Vector, Void> though. (Note the difference between void, which is a Java keyword, and Void which refers to the java.lang.Void type.)

    Personally I'd suggest using List<E> in preference to explicitly using Vector, and using it generically if possible, with ArrayList<E> as an implementation rather than Vector, but that's a separate matter - it's only the void / Void which is causing you immediate problems.