SwingWorker:类型的非法开始

发布于 2025-01-04 08:35:55 字数 1356 浏览 0 评论 0原文

这是一段代码导致了我的问题:

   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(); 

这一行:

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

给出错误:非法开始类型... 我认为我的问题是由于“向量”引起的,但我不知道如何解决.. 有什么帮助吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你在看孤独的风景 2025-01-11 08:35:55

不,问题是使用了 void,它不是有效的类型参数。不过,您可以使用 SwingWorker。 (请注意 Java 关键字 void 和引用 java.lang.Void 类型的 Void 之间的区别。

)建议优先使用 List 而不是显式使用 Vector,并在可能的情况下一般使用它,并使用 ArrayList 作为实施而不是Vector,但这是一个单独的问题 - 只有 void / Void 会导致您立即出现问题。

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.

甜味超标? 2025-01-11 08:35:55

第二个问题是关于 SwingWorker 的 void done() 中方法 get() 的错误使用,因为仅返回来自 SwingWorker(且仅当存在异常时),有关方法 get() 在我的问题

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文