Can not find a java.io.InputStream with the name [inputStream] in the invocation stack

本文介绍了一种在使用Java导出Excel文件时遇到的问题及解决方案。主要问题是当数据不完整时,导出过程中会抛出关于InputStream的异常。通过判空处理,将null值设为字符来避免异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      我在做Excel文件导出的时候,业务 和  实现 不是写在一个系统里面的,所以输出的时候用的是以字节流的形式输出  

	try {
	       ByteArrayOutputStream os = new ByteArrayOutputStream();
	       workBook.write(os);

	       bytes = os.toByteArray();
	       os.close();
	   } catch (IOException e) {
	       return null;
	   }


	try {
            downloadFileName = "aps-mch-cls" + "-" + sdf.format(startDate) + "-" + sdf.format(endDate) + ".xlsx";
            String[] titles = { "结算编号", "商户编号", "商户名称","结算净额(元)","银行名称","账户类别","户名","账号","结果" };
            //response.setHeader("Content-Disposition", "attachment;filename="+fileName);
            byte[] bytes = mechSettlementQueryAppService.exportToExcel(titles, clearSettleSearch);
            
            inputStream = new ByteArrayInputStream(bytes); 
        } catch (Exception e) {
            e.printStackTrace();
        }

测试的时候,导出的数据都是完整的,就是每一行每一列都是有数据的,没有考虑其他情况,所以当发布到生产环境上的时候,数据库的数据不完整,也就是说不是每一行每一列都有数据,这时候就出现了一个问题,就是Can not find a java.io.InputStream with the name [inputStream] in the invocation stack。

查看下官方源码:

	if (inputStream == null) {
              // Find the inputstream from the invocation variable stack
              inputStream = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation));
          }
        if (inputStream == null) {
            String msg = ("Can not find a java.io.InputStream with the name [" + inputName + "] in the invocation stack. " +
                 Check the <param name=\"inputName\"> tag specified for this action.");
            LOG.error(msg);
            throw new IllegalArgumentException(msg);
          }

当inputStream有null的时候就会抛出异常。


所以我在设置有可能为空的 cell的时候做了判空处理,将null 设置为""字符,这样就不会出现异常了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值