JPA + SwingWorker:查询错误

发布于 2025-01-04 03:07:58 字数 6076 浏览 0 评论 0原文

我有一个名为“jf_suggestion”的 JFrame 包含一个最初为空的 JList,它将由 DB 中的 String 列表填充,其名为“jf_seggestion_liste”。 每当用户在名为“libel_article”的 JXFormatedTextField 中键入字符时,就会显示此 Jframe&JList。

这是一个定制的建议系统...以下是源代码:

  //This is the method of triggering event
 private void libel_articleKeyTyped(java.awt.event.KeyEvent evt) {                                       

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

        @Override
        protected Vector doInBackground() throws Exception {
            ArticleJpaController ajc=null;

        Vector l_article=(Vector) ajc.finArticleBylibelle(libel_article.getText());

        return l_article;
        }

       @Override
     protected void done(){
            Vector l_article=null;
            try {
               l_article=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);
            }


             // filling the JList by ​​recovered values 
            jf_seggestion_liste.setListData(l_article);
             //we display our suggestion box
          jf_suggestion.setVisible(true);



 //recovering the size of our JXForamtedTextField  
   Rectangle rect = libel_article.getBounds();

 //we create a new rectangle & setbounds(...) to the JFrame
   Rectangle rectc = new Rectangle(rect.x+rect.width+23, rect.y+rect.height, 250, 350);
   jf_suggestion.setBounds(rectc);
     }

};

  sw.execute();  

}         

检索列表的方法字符串:

   public List<String> finArticleBylibelle(String libelle){
     EntityManager em = getEntityManager();
    Query qr= em.createQuery("SELECT a.libel FROM Article a WHERE   a.libel='"+libelle+"'");
   return qr.getResultList();
   }

我也尝试过:

   public List<String> finArticleBylibelle(String libelle){
     EntityManager em = getEntityManager();
    Query qr= em.createQuery("SELECT a.libel FROM Article a");
   return qr.getResultList();
   }

我收到此错误(在 l_article=get(); 行中):

    java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
at java.util.concurrent.FutureTask.get(FutureTask.java:111)
at javax.swing.SwingWorker.get(SwingWorker.java:602)
at glob.main$20.done(main.java:1241)
at javax.swing.SwingWorker$5.run(SwingWorker.java:737)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:832)
at sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)
at    javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:842)
at javax.swing.Timer.fireActionPerformed(Timer.java:312)
at javax.swing.Timer$DoPostEvent.run(Timer.java:244)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at   java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at   java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Caused by: java.lang.NullPointerException
at glob.main$20.doInBackground(main.java:1232)
at glob.main$20.doInBackground(main.java:1226)
at javax.swing.SwingWorker$1.call(SwingWorker.java:296)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at javax.swing.SwingWorker.run(SwingWorker.java:335)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.JList$5.getSize(JList.java:1722)
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1342)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1311)
at javax.swing.plaf.basic.BasicListUI.getPreferredSize(BasicListUI.java:578)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1660)
at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:790)
at java.awt.Container.layout(Container.java:1503)
at java.awt.Container.doLayout(Container.java:1492)
at java.awt.Container.validateTree(Container.java:1688)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validate(Container.java:1623)
at java.awt.Container.validateUnconditionally(Container.java:1660)
at java.awt.Window.show(Window.java:1032)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1013)
at glob.main$20.done(main.java:1252)
at javax.swing.SwingWorker$5.run(SwingWorker.java:737)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:832)
at sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)

请帮忙!

I have a JFrame named "jf_suggestion" contains a JList initially empty, it will be filled by a list of String from DB , its named "jf_seggestion_liste".
This Jframe&JList is displayed whenever the user types a character in the JXFormatedTextField its named "libel_article"..

This is a customized suggestion system... Here's the source code :

  //This is the method of triggering event
 private void libel_articleKeyTyped(java.awt.event.KeyEvent evt) {                                       

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

        @Override
        protected Vector doInBackground() throws Exception {
            ArticleJpaController ajc=null;

        Vector l_article=(Vector) ajc.finArticleBylibelle(libel_article.getText());

        return l_article;
        }

       @Override
     protected void done(){
            Vector l_article=null;
            try {
               l_article=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);
            }


             // filling the JList by ​​recovered values 
            jf_seggestion_liste.setListData(l_article);
             //we display our suggestion box
          jf_suggestion.setVisible(true);



 //recovering the size of our JXForamtedTextField  
   Rectangle rect = libel_article.getBounds();

 //we create a new rectangle & setbounds(...) to the JFrame
   Rectangle rectc = new Rectangle(rect.x+rect.width+23, rect.y+rect.height, 250, 350);
   jf_suggestion.setBounds(rectc);
     }

};

  sw.execute();  

}         

the method that retrieves the list of Strings :

   public List<String> finArticleBylibelle(String libelle){
     EntityManager em = getEntityManager();
    Query qr= em.createQuery("SELECT a.libel FROM Article a WHERE   a.libel='"+libelle+"'");
   return qr.getResultList();
   }

I also tried :

   public List<String> finArticleBylibelle(String libelle){
     EntityManager em = getEntityManager();
    Query qr= em.createQuery("SELECT a.libel FROM Article a");
   return qr.getResultList();
   }

I get this Error (in the line l_article=get();):

    java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
at java.util.concurrent.FutureTask.get(FutureTask.java:111)
at javax.swing.SwingWorker.get(SwingWorker.java:602)
at glob.main$20.done(main.java:1241)
at javax.swing.SwingWorker$5.run(SwingWorker.java:737)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:832)
at sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)
at    javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:842)
at javax.swing.Timer.fireActionPerformed(Timer.java:312)
at javax.swing.Timer$DoPostEvent.run(Timer.java:244)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at   java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at   java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Caused by: java.lang.NullPointerException
at glob.main$20.doInBackground(main.java:1232)
at glob.main$20.doInBackground(main.java:1226)
at javax.swing.SwingWorker$1.call(SwingWorker.java:296)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at javax.swing.SwingWorker.run(SwingWorker.java:335)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.JList$5.getSize(JList.java:1722)
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java:1342)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI.java:1311)
at javax.swing.plaf.basic.BasicListUI.getPreferredSize(BasicListUI.java:578)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1660)
at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:790)
at java.awt.Container.layout(Container.java:1503)
at java.awt.Container.doLayout(Container.java:1492)
at java.awt.Container.validateTree(Container.java:1688)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validate(Container.java:1623)
at java.awt.Container.validateUnconditionally(Container.java:1660)
at java.awt.Window.show(Window.java:1032)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1013)
at glob.main$20.done(main.java:1252)
at javax.swing.SwingWorker$5.run(SwingWorker.java:737)
at javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:832)
at sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)

HELPS PLEASE!

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

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

发布评论

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

评论(1

紧拥背影 2025-01-11 03:07:58
java.util.concurrent.ExecutionException: java.lang.NullPointerException

正如您在此异常中所看到的,您似乎使用了空变量。检查您的代码并再次返回您的反馈;)

java.util.concurrent.ExecutionException: java.lang.NullPointerException

As you can see in this exception, you seems using a null variable. Check your code and back again with your feedback ;)

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