gpt4 book ai didi

java - JPA + SwingWorker : Query Error

转载 作者:行者123 更新时间:2023-12-02 07:58:42 24 4
gpt4 key购买 nike

我有一个名为“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)

请帮忙!

最佳答案

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

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

关于java - JPA + SwingWorker : Query Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9235347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com