For input string: "null"
java.lang.NumberFormatException: For input string: "null"
在开发中你是否遇到过这样的问题,不管请求到的值是什么都能进入不为null或”“的判断中,如下例:
Stringtemp=req.getParameter("status");//任务状态
int status= 0;//任务状态
if(temp!=null&&!"".equals(temp))
{
status=Integer.parseInt(temp);
}
json.put("status",status);
运行时temp总能进入if条件判断,并且你会得到错误提示如下:
java.lang.NumberFormatException: For inputstring: "null"
atjava.lang.NumberFormatException.forInputString(NumberFormatException.
java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
atcom.runqianapp.workflow.servlet.WorkShowServlet.getJson(WorkShowServl
et.java:102)
atcom.runqianapp.workflow.servlet.WorkShowServlet.doPost(WorkShowServle
t.java:49)
atjavax.servlet.http.HttpServlet.service(HttpServlet.java:709)
atjavax.servlet.http.HttpServlet.service(HttpServlet.java:802)
atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:237)
atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:157)
这是为什么呢?我再着困扰了好长时间才找到原因,其实是错误的理解了提示 Forinput string: "null"
这句话的意思不是输入的是空值,而是说你输入的事String类型的字符串”null“
明白为什么错了就好解决了,解决方法如下:
Stringtemp=req.getParameter("status");//任务状态
int status= 0;//任务状态
if(temp!=null&& !"".equals(temp) &&!"null".equals(temp))
{
status=Integer.parseInt(temp);
}
json.put("status",status);
只需要加上一条不为字符串”null“的判断即可
For input string: "null"的更多相关文章
- NumberFormatException: For input string: "null"
日志: [INFO-2016/08/04/16/:21/:25]ProjectCommonFormController.(78) - 审批[同意]入参-[string]commonFormDtoStr ...
- myBatis-plus异常提示For input string: "{0=null}"
异常信息 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Per ...
- java.lang.NumberFormatException: For input string: "Y"
nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. ...
- mybatis 报错:Caused by: java.lang.NumberFormatException: For input string
mybatis的if标签之前总是使用是否为空,今天要用到字符串比较的时候遇到了困难,倒腾半天,才在一个论坛上找到解决方法.笔记一下,如下: 转自:https://code.google.com/p/m ...
- MyBatis报错:Caused by: java.lang.NumberFormatException: For input string: "XX"
<select id="sltTreatment" resultType="com.vitaminmd.sunny.core.bo.Treatment"& ...
- For input string: "..."
之前在项目中通过EL表达式从cart 中取出itemPirce这个值时始终报:For input string: "${cart.itemPrice / 100}" 错误. 事故原 ...
- org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NumberFormatException: For input string: "W%" ### Cause: java.lang.NumberFormatException: For input s
一个常见的myBatis xml文件中的引号错误: org.apache.ibatis.exceptions.PersistenceException: ### Error querying data ...
- java.lang.NumberFormatException: For input string: "1608020001 " 错误
错误: java.lang.NumberFormatException: For input string: "1608020001 " at java.lang.Numbe ...
- java.lang.NumberFormatException: For input string:"filesId"
做项目时候,页面获取出现了这个问题.找了好久一直以为是我字段或者是数据库字段问题导致引起的. 最后才发现是 struts2中jsp我写错了一个参数,一直导致报错.后来改了就好了. 当大家遇到这个问题的 ...
随机推荐
- keras运行gan的几个bug解决
http://blog.csdn.net/u012317000/article/details/79211274 https://www.jianshu.com/p/5b1f7004144d
- Excel_To_DataTable
/// <summary> /// Read data in excel file to datatable /// </summary> /// <param name ...
- Linux命令详解-pwd
Linux中用 pwd 命令来查看"当前工作目录"的完整路径. 简单得说,每当你在终端进行操作时,你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文 ...
- 11.深入理解读写锁ReentrantReadWriteLock
protected final int tryAcquireShared(int unused) { /* * Walkthrough: * 1. If write lock held by anot ...
- 玲珑oj 1028 贪心
http://www.ifrog.cc/acm/problem/1028 很有趣的一道题,求从n个数里挑出不同的两个,使得他俩'|','&','^'后的值尽量大,求这个最大的结果. 求最大的异 ...
- Highcharts 基本区域图;Highcharts 使用负数区域图;Highcharts 堆叠区域图;Highcharts 百分比堆叠区域图
Highcharts 基本区域图 配置 chart chart.type 配置项用于设定图表类型,默认为 "line",本章节我们使用 'area'. var chart = { ...
- 尝试优化骨骼动画计算的意外收获——使用嵌入式汇编对float转int进行优化
本文为大便一箩筐的原创内容,转载请注明出处,谢谢:http://www.cnblogs.com/dbylk/p/4984530.html 公司引擎目前是使用CPU计算骨骼动画(采用了D3DX提供的函数 ...
- C# 与vb.net 的Dictionary(字典)的键、值排序
项目中可能需要用到Dictionary 排序,于是先做了一个小demo ,网上搜索真的没有能满足我需要的,都是类似的,于是理解改造,一上午就在查找,实践中过去了.现在把它实现了,把代码贴出来,算是一个 ...
- SSM整合RocketMQ
前言 RocketMQ是一个由阿里巴巴开源的消息中间件,脱胎于阿里内部使用的MetaQ,本文主要是写个小例子演示一下消息从生产到消费的过程. RocketMQ下载和安装 下载地址 http://roc ...
- 单例类singleton自动释放
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...