天过无痕 2019-11-01 15:02 采纳率: 0%
浏览 780
已采纳

ssh框架,接口实现类调用service方法报空指针异常

            //**实现类代码**
            String tname = saleName;
            String id =  goodIds;
            //调用service层方法,传入两个参数。报空指针
            int count = tpcCombinationSaleService.querySaleindexName(tname, id);


            //**service代码**
            public int querySaleindexName(String indexName,String id)
            throws com.sinovatech.common.exception.AppException;


            //**impl代码**
            @Override
    public int querySaleindexName(String indexName,String id) throws com.sinovatech.common.exception.AppException {
        indexName = indexName.trim();
        String sql="";
        if(!id.equals("")){
            sql = "select * from DATA_RRYX.T_PC_COMBINATION_SALE Z where Z.NAME='" + indexName + "' and Z.id <> '"+id+"' and Z.is_delete = 'N'";
        }else{
            sql = "select * from DATA_RRYX.T_PC_COMBINATION_SALE Z where Z.NAME='" + indexName + "'  and Z.is_delete = 'N'";
        }
        return tpcCombinationSaleDAO.getRecordCountBySQL(sql);

以上为代码,现在我运行测试类正常传参进去后,debug的时候走到调用service方法,没有走方法内部,就直接跳转到Thread类,的dispatchUncaughtException方法,然后就报了空指针异常,请问大佬们可能的原因是在哪里?

  • 写回答

2条回答 默认 最新

  • zhshchilss 2019-11-01 16:49
    关注

    1.确保tpcCombinationSaleService不是null,打断点看一下
    2.确保两个参数是否为null
    3.如果都没问题,断点打到这一行 indexName = indexName.trim(); 然后一步一步debug看哪一行有问题
    4.报的错有没有说是哪一行

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?