我是新的Java EE中,我試圖創建一個從數據庫中收集信息的方法。它給我以下錯誤:java.lang.NullPointerException查詢調用
java.lang.NullPointerException
at com.universite.bean.checkmatiere.check(checkmatiere.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:779)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:528)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:257)
at com.sun.el.parser.AstValue.getValue(AstValue.java:134)
at com.sun.el.parser.AstValue.getValue(AstValue.java:183)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
這是我的check
方法。它給了我一個錯誤,當我調用trouver
方法:
public void check() {
etudiant =(Etudiant) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("etudiant");
n=etudiant.getniveau();
result =matiereDao.trouver(n);
if(result.size()!=0) {
Iterator<Matiere> stIterator=result.iterator();
while(stIterator.hasNext()){
matiere=(Matiere)stIterator.next();
FacesMessage message = new FacesMessage("matire: "+ matiere.getNom());
FacesContext.getCurrentInstance().addMessage(null,message);
nummatiere=matiere.getIdmatiere();
private List<Chapitre> result1;
/*line 49*/ result1 =chapitredao.trouver(nummatiere);
if (result1!= null)
{if(result1.size()!=0)
{
Iterator<Chapitre> stIterator1=result1.iterator();
while(stIterator1.hasNext()){
chapitre=(Chapitre)stIterator1.next();
FacesMessage message1 = new FacesMessage("chapitre: "+chapitre.getNomchapitre());
FacesContext.getCurrentInstance().addMessage(null,message1);
}
} }
}
}
else {
FacesMessage message = new FacesMessage("echec !");
FacesContext.getCurrentInstance().addMessage(null,message);
}
這是我的「已找到」功能
private static final String JPQL_SELECT_PAR_nummatiere= "SELECT ufFROM Chapitre uf where uf.nummatiere=:nummatiere";
private static final String PARAM_nummatiere = "nummatiere";
public List<Chapitre> trouver(int nummatiere ) throws DAOException {
Query requete1 = entitymanager.createQuery(JPQL_SELECT_PAR_nummatiere);
requete1.setParameter(PARAM_nummatiere, nummatiere);
try {
results2 = requete1.getResultList();
} catch (NoResultException e) {
return null;
} catch (Exception e) {
throw new DAOException(e);
}
return results2;
}
感謝所有幫助你可以給。我一直堅持這個錯誤三天了。
它與JSF有關嗎?如果是這樣的標籤。 – Lion 2013-04-22 22:27:04
checkmatiere課程的49行內容是什麼? – 2013-04-22 22:33:33
在第49行檢查你的n值 – 2013-04-22 22:39:57