2012-04-06 63 views
1

我一直在这里收到此错误:无法解决:java.lang.NumberFormatException:对于输入字符串:“”

SEVERE: java.lang.NumberFormatException: For input string: "" 
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) 
at java.lang.Integer.parseInt(Integer.java:504) 
at java.lang.Integer.parseInt(Integer.java:527) 
at com.myapp.cmt.web.ContentController.saveContent(ContentController.java:129) 

在下拉菜单中选择了categories我的网页上没有选择它发生。我正在检查长度,所以它怎么还在试图处理parseInt()

 String[] category = request.getParameterValues("categories"); 
     if (category.length > 0) { 
      content.addCategory(contentDao.findCategory(Integer.parseInt(category[0]))); 
     } 

我的HTML

<strong>Category</strong><br/> 
    <select name="categories"> 
     <option></option> 
    <c:forEach items="${categories}" var="category"> 
     <option value="${category.id}" <c:if test="${content.hasCategory(category)}"> CHECKED</c:if>>${category.name}</option> 
    </c:forEach> 
    </select> 

回答

0

您的数组的长度只有故事......你必须还要检查什么在阵列一半。尝试一下这样的代码:

if (category.length > 0 && 
    category[0] != null && 
    category[0].trim().length() > 0) 
    content.addCategory(contentDao.findCategory(Integer.parseInt(category[0]))); 
} 
0

返回类的空单元素。在你的if语句,你也应该检查category[0] != null && !"".equals(category[0].trim())

相关问题