java.lang.NullPointerException
at com.esoft.wuliu.web.action.system.VehicleMgrAction.showUpdate(VehicleMgrAction.java:121)
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:613)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:148)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:128)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:148)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:128)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:717)
vehicle=vehicleManager.get(vid);这条鱼局没有获取到直。我也有封装,怎么还是没有获取到呢?

解决方案 »

  1.   

    com.esoft.wuliu.web.action.system.VehicleMgrAction的showUpdate方法出现空指针,鉴定完毕。
    不要忘了结贴
      

  2.   

    vehicleManager为空,还是把代码贴多点吧。
      

  3.   

    package com.esoft.wuliu.web.action.system;import java.io.InputStream;
    import java.io.StringBufferInputStream;
    import java.util.List;import com.esoft.wuliu.model.system.Vehicle;
    import com.esoft.wuliu.service.system.VehicleManager;
    import com.opensymphony.xwork2.ActionContext;
    import com.opensymphony.xwork2.ActionSupport;public class VehicleMgrAction extends ActionSupport { private VehicleManager vehicleManager;

    private Vehicle vehicle;

    private Integer vid;

    private InputStream inputStream;

    private int id;

    private List<Integer> ids;

    private int currentPage=1;

    /**
     * 显示所有车辆
     * @return
     */
    public String list(){
    ActionContext ctx=ActionContext.getContext();
    int pageCount=5;
    int totalPage = 0;
    int totalCount = 0;
    int pageStartRow = 0; // 计算总记录数
    totalCount = vehicleManager.showList().size(); // 计算总页数
    if (totalCount % pageCount == 0) {
    totalPage = totalCount / pageCount;
    } else {
    totalPage = totalCount / pageCount + 1;
    } // 修改currentPage,保证1<=currentPage<=totalPage
    if (currentPage < 1) {
    currentPage = 1;
    } else if (currentPage > totalPage) {
    currentPage = totalPage;
    } // 计算当前页第一条记录的索引号
    pageStartRow = (currentPage - 1) * pageCount;
    List<Vehicle> list = vehicleManager.showPage(pageStartRow, pageCount); ctx.put("pageCount", pageCount);
    ctx.put("totalCount", totalCount);
    ctx.put("totalPage", totalPage);
    ctx.put("list", list);
    return SUCCESS;
    }
    /**
     * 显示添加页面
     * @return
     */
    public String showAdd(){
    return SUCCESS;
    }
    /**
     * 添加车辆
     * @return
     */
    public String add(){
    if(vehicleManager.save(vehicle)){
    return SUCCESS;
    }else{
    ActionContext.getContext().put("error","添加车辆失败");
    return ERROR;
    }
    }
    /**
     * 判断车辆是否存在
     * @return
     */
    public String check(){
    try{
    if(vid!=null&&!"".equals(vid)){
    if(vehicleManager.ckVehiclevid(vid)){
    inputStream = new StringBufferInputStream("valid");
    } else {
    inputStream = new StringBufferInputStream("invalid");
    }
    }
    }catch(Exception e){
    e.printStackTrace();
    }
    return SUCCESS;
    }
    /**
     * 删除车辆
     * @return
     */
    public String delete(){
    try{
    vehicleManager.delete(id);
    }catch(Exception e){
    e.printStackTrace();
    }
    return SUCCESS;
    }
    /**
     * 显示修改页面
     * @return
     */
    public String showUpdate(){
    try{
    vehicle=vehicleManager.get(vid);

    }catch(Exception e){
    e.printStackTrace();
    }
    return SUCCESS;
    }
    /**
     * 修改
     * @return
     */
    public String update(){
    try{
    vehicleManager.update(vehicle);
    }catch(Exception e){
    e.printStackTrace();
    }
    return SUCCESS;
    }
    public List<Integer> getIds(){
    return this.ids=ids;
    } public void setIds(List<Integer> ids) {
    this.ids = ids;
    } public int getCurrentPage() {
    return currentPage;
    } public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
    } public Integer getVid() {
    return vid;
    } public void setVid(Integer vid) {
    this.vid = vid;
    } public Vehicle getVehicle() {
    return vehicle;
    } public void setVehicle(Vehicle vehicle) {
    this.vehicle = vehicle;
    } public VehicleManager getVehicleManager() {
    return vehicleManager;
    } public void setVehicleManager(VehicleManager vehicleManager) {
    this.vehicleManager = vehicleManager;
    }
    public int getId() {
    return id;
    }
    public void setId(int id) {
    this.id = id;
    }


    }
    这是action的代码
      

  4.   

    function showAdd() {
    location.href = "${path}/system/vehicle/showAdd.action";
    }// 全选
    function checkAll() {
    var ids = document.getElementsByName("ids");
    for ( var i = 0; i < ids.length; i++) {
    ids[i].checked = document.getElementById("checkList").checked;
    }
    }function deleteCheck() {
    var ids = document.getElementsByName("ids");
    var flag = false;
    for ( var i = 0; i < ids.length; i++) {
    if ( ids[i].checked==true ) {
    flag = true;
    break;
    }
    }
    if(!flag) {
    alert("请选择要删除的数据!");
    return false;
    }
    if(confirm("确认删除这些数据吗?")) {
    var f = document.getElementById("fList");
    var url = "${path}/system/emp/deleteCheck.action";
    f.action = url;
    f.submit();
    }
    }function go() {
    var cp = document.getElementById("cp").value;
    location.href = "${path}/system/emp/list.action?currentPage=" + cp;
    }//仅允许输入数字
    function checkNumber() {
        //判断输入字符的keyCode,数字在48到57之间,超出部分返回false
        if ((event.keyCode >= 48) && (event.keyCode <= 57)) {
            event.returnValue = true;
        } else {
            event.returnValue = false;
        }
    }
    </script>
    </head><body>
    <form id="fList">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="30" background="${path}/images/tab_05.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="12" height="30"><img src="${path}/images/tab_03.gif" width="12" height="30" /></td>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="46%" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                </tr>
                  <tr>
                    <td width="5%"><div align="center"><img src="${path}/images/tb.gif" width="16" height="16" /></div></td>
                    <td width="95%" class="STYLE1"><span class="STYLE3">您当前的位置</span>:[车辆管理]-[车辆信息管理]</td>
                  </tr>
                </table></td>
                <td width="54%"><table border="0" align="right" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="60"><table width="90%" border="0" cellpadding="0" cellspacing="0">
                      <tr onclick="showAdd()" style="cursor:hand">
                        <td class="STYLE1"><div align="center"><img src="${path}/images/22.gif" width="14" height="14" /></div></td>
                        <td class="STYLE1"><div align="center">新增</div></td>
                      </tr>
                    </table></td>
                    <td width="100"><table width="88%" border="0" cellpadding="0" cellspacing="0">
                      <tr onclick="return deleteCheck()" style="cursor:hand">
                        <td class="STYLE1"><div align="center"><img src="${path}/images/11.gif" width="14" height="14" /></div></td>
                        <td class="STYLE1"><div align="center">删除选中</div></td>
                      </tr>
                    </table></td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
            <td width="16"><img src="${path}/images/tab_07.gif" width="16" height="30" /></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="" background="${path}/images/tab_12.gif">&nbsp;</td>
            <td><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="b5d6e6" onmouseover="changeto()"  onmouseout="changeback()">
              <tr>
                <td width="3%" height="15" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center">
                  <input type="checkbox" id="checkList" onclick="checkAll()" />
                </div></td>
                <td width="4%" height="10" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">车辆编号</span></div></td>
                <td width="6%" height="10" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">所属车队</span></div></td>
                <td width="6%" height="10" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">车牌号码</span></div></td>
                <td width="6%" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">车辆类型</span></div></td>
                
                <td width="6%" height="10" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">车辆载重</span></div></td>
                <td width="5%" height="15" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">车辆状态</span></div></td>
                
                 <td width="5%" height="10" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">备注</span></div></td>
                 
                        
                         <td width="10%" height="15" background="${path}/images/bg1.gif" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">操作</span></div></td>
              </tr>
              
              <c:forEach items="${list}" var="item">
              <tr>
                <td height="8" bgcolor="#FFFFFF"><div align="center">
                  <input type="checkbox" name="ids" value="${item.vid }" />
                </div></td>
                <td height="8" bgcolor="#FFFFFF"><div align="center" class="STYLE1">
                  <div align="center">${item.vid }</div>
                </div></td>
             
       
                 <td height="5" bgcolor="#FFFFFF" ><div align="center"><span class="STYLE1">${item.motorcade.mid }</span></div></td>
                <td height="5" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${item.vname}</span></div></td>
                
                <td height="15" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${item.vtype}</span></div></td>
                <td height="15" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${item.vweight}</span></div></td>
                <td height="15" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${item.vstatution}</span></div></td>
                <td height="15" bgcolor="#FFFFFF"><div align="center"><span class="STYLE1">${item.re}</span></div></td>
                
                
               
                <td height="15" bgcolor="#FFFFFF"><div align="center"><span class="STYLE4"><a href="${path}/system/vehicle/showUpdate.action?id=${item.vid }"><img src="${path}/images/reply.gif" width="16" height="16" />编辑</a><a href="${path}/system/vehicle/delete.action?id=${item.vid }" onclick="return confirm('确认删除该数据吗?')"><img src="${path}/images/del.gif" width="16" height="16" />删除</a></span></div></td>
              </tr>
              </c:forEach>
              
            </table></td>
            <td width="8" background="${path}/images/tab_15.gif">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="35" background="${path}/images/tab_19.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="12" height="35"><img src="${path}/images/tab_18.gif" width="12" height="35" /></td>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td class="STYLE4">&nbsp;&nbsp;共有 ${requestScope.totalCount } 条记录,当前第 ${requestScope.currentPage }/${requestScope.totalPage } 页</td>
                <td><table border="0" align="right" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="40"><a href="${path}/system/manager/list.action?currentPage=1"><img src="${path}/images/first.gif" width="37" height="15" /></a></td>
                      <td width="45"><a href="${path}/system/manager/list.action?currentPage=${requestScope.currentPage-1 }"><img src="${path}/images/back.gif" width="43" height="15" /></a></td>
                      <td width="45"><a href="${path}/system/manager/list.action?currentPage=${requestScope.currentPage+1 }"><img src="${path}/images/next.gif" width="43" height="15" /></a></td>
                      <td width="40"><a href="${path}/system/manager/list.action?currentPage=${requestScope.totalPage }"><img src="${path}/images/last.gif" width="37" height="15" /></a></td>
                      <td width="100"><div align="center"><span class="STYLE1">转到第
                        <input id="cp" onkeypress="checkNumber()" type="text" size="4" style="height:12px; width:20px; border:1px solid #999999;" /> 
                        页 </span></div></td>
                      <td width="40"><img src="${path}/images/go.gif" width="37" height="15" onclick="go()"  style="cursor:hand"/></td>
                    </tr>
                </table></td>
              </tr>
            </table></td>
            <td width="16"><img src="${path}/images/tab_20.gif" width="16" height="35" /></td>
          </tr>
        </table></td>
      </tr>
    </table>
    </form>
    </body>
    </html>
    这是list.jsp部分代码
      

  5.   

    vehicleManager 有值么
    判断下vehicleManager==null
      

  6.   

    vehicle=vehicleManager.get(vid);只有一种可能,就是 vehicleManager是null.
      

  7.   

    private VehicleManager vehicleManager;lz看下,是否注入成功
      

  8.   

    和vid没关系吧,你看看7楼说的, VehicleManager vehicleManager是否注入成功
      

  9.   

    vehicle=vehicleManager.get(vid);这句里的vehicle始终是获取不到得
      

  10.   

    空指针这样异常应该是很好解决的啊:
    vehicle=vehicleManager.get(vid);
    vehicle如果为空,那么肯定就是vehicleManager.get(vid);
    返回值为空,原因呢,要门vid根本就没有获取到,要么get(vid)没有查询到,再要么vehicleManager实例为空,你只要挨着排查这三个就可以了
      

  11.   

    vid的值没有,当然那个会引起空指针异常了,可以进行判断
    if(vid==null){
       如何如何
    }
    else{
       如何如何
    }
    你这个vid是否是从jsp页面传入的值??
      

  12.   

    又看了一下楼主的jsp代码,觉得存在问题。就是你action里的vid在jsp里没有对应项,还有代码太乱,不容易让人理解,楼主应该整理思路重新设计