0

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 ?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Marwen Trabelsi
  • 4,167
  • 8
  • 39
  • 80

2 Answers2

3

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 1
    @MarwenTrabelsi: What about it? That uses `Void` rather than `void` everywhere I can see. – Jon Skeet Feb 10 '12 at 14:50
  • Solved, SwingWorker its work, but I do not understand what is the interest of second parameter, this is ridiculous ... – Marwen Trabelsi Feb 10 '12 at 14:52
  • 1
    @MarwenTrabelsi: It's not ridiculous - you just don't seem to have read my answer carefully enough: `void` is simply not a valid type argument. `Void` is, because that's the name of a type. `void` is *not* the name of a type, as such. You've tried `SwingWorker` but did you try the suggestion frmo my answer of `SwingWorker`? – Jon Skeet Feb 10 '12 at 14:59
  • @MarwenTrabelsi: Exactly. Do you understand now, and not regard it as ridiculous any more? – Jon Skeet Feb 10 '12 at 15:03
2

and second issue is that about wrong usage of method get() into SwingWorker's void done(), because returns only exception from SwingWorker (and only if exception exists), more about usage of method get() in my question

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319