2013-02-05 180 views
0

我有以下的錯誤與我的項目Primefaces顯示java.lang.NullPointerException

嚴重:收到 '顯示java.lang.NullPointerException' 調用動作 聽衆 '#{} tableBean.addNew' 當組件 'loginButton'重度: 顯示java.lang.NullPointerException

這是我ADDNEW功能:

public void addNew(ActionEvent actionEvent) throws SQLException { 
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 

     initiate_ddate=sdf.format(initiateddate); 
     teststart_date=sdf.format(teststartdate); 
     scheduledend_date=sdf.format(scheduledenddate); 
     revised_end=sdf.format(revisedend); 


     System.err.println("erorrrrrrrrrr"); 

     Connection connadd = new Connector().getConn(); 
     Statement stmt = connadd.createStatement(); 

     String sql2 = "INSERT INTO status (`name`, `initiateddate`, `agreementstatus`, `testingdoc`, `teststartdate`, `scheduledenddate`, `teststatus`, `revisedend`, `launcstatus`) VALUES ( '" + name + "' , '" + initiate_ddate + "' , '" + agreement_status + "', '" + testing_doc + "', '" + teststart_date + "', '" + scheduledend_date + "', '" + test_status + "', '" + revised_end + "', '" + launc_status + "'); "; 

     stmt.executeUpdate(sql2); 
     FacesMessage msg = new FacesMessage("Project Edited", name + " " + initiate_ddate + " " + agreement_status + " " + testing_doc + " " + teststart_date + " " + scheduledend_date + " " + test_status + " " + revised_end + " " + launc_status); 

     FacesContext.getCurrentInstance().addMessage(null, msg); 
    } 

這是什麼原因?

這是堆棧跟蹤:

SEVERE: Received 'java.lang.NullPointerException' when invoking action listener '#{tableBean.addNew}' for component 'loginButton' 
SEVERE: java.lang.NullPointerException 
    at java.util.Calendar.setTime(Calendar.java:1070) 
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:859) 
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:852) 
    at java.text.DateFormat.format(DateFormat.java:316) 
    at table.TableBean.addNew(TableBean.java:192) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at com.sun.el.parser.AstValue.invoke(AstValue.java:254) 
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302) 
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) 
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148) 
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88) 
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769) 
    at javax.faces.component.UICommand.broadcast(UICommand.java:300) 
    at javax.faces.component.UIData.broadcast(UIData.java:1093) 
    at javax.faces.component.UIData.broadcast(UIData.java:1093) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542) 
    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:849) 
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) 
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) 
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) 
    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:619) 

SEVERE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=form_tab:tabView, Message=/index.xhtml @234,223 actionListener="#{tableBean.addNew}": java.lang.NullPointerException 
SEVERE: /index.xhtml @234,223 actionListener="#{tableBean.addNew}": java.lang.NullPointerException 
javax.faces.event.AbortProcessingException: /index.xhtml @234,223 actionListener="#{tableBean.addNew}": java.lang.NullPointerException 
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182) 
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88) 
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769) 
    at javax.faces.component.UICommand.broadcast(UICommand.java:300) 
    at javax.faces.component.UIData.broadcast(UIData.java:1093) 
    at javax.faces.component.UIData.broadcast(UIData.java:1093) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542) 
    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:849) 
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) 
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) 
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) 
    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:619) 
Caused by: java.lang.NullPointerException 
    at java.util.Calendar.setTime(Calendar.java:1070) 
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:859) 
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:852) 
    at java.text.DateFormat.format(DateFormat.java:316) 
    at table.TableBean.addNew(TableBean.java:192) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at com.sun.el.parser.AstValue.invoke(AstValue.java:254) 
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302) 
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) 
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148) 
    ... 35 more 
+0

能否請您發佈的堆棧跟蹤。這是知道實際原因的最好方法 – Reddy

+0

可能有多個原因爲空指針,發佈你的棧跟蹤將幫助 – TheWhiteRabbit

+0

我發佈我的棧跟蹤 – user1705260

回答

1

NullPointerException異常通常是很容易解決,在此情況下:

訣竅是在堆棧跟蹤尋找一段代碼你自己

SEVERE: java.lang.NullPointerException 
    at java.util.Calendar.setTime(Calendar.java:1070) 
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:859) 
    at java.text.SimpleDateFormat.format(SimpleDateFormat.java:852) 
    at java.text.DateFormat.format(DateFormat.java:316) 
    at table.TableBean.addNew(TableBean.java:192) 

在這種情況下,它是table.TableBean.addNew方法在DateFormat上執行格式

你做這些的4(我不知道什麼是對行192):

initiate_ddate=sdf.format(initiateddate); 
teststart_date=sdf.format(teststartdate); 
scheduledend_date=sdf.format(scheduledenddate); 
revised_end=sdf.format(revisedend); 

的根本原因在於以下變量之一爲null。它被傳遞到格式化功能,並拋出一個NPE

  • initiateddate
  • teststartdate
  • scheduledenddate
  • revisedend
相關問題