| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 821 人关注过本帖
标题:这此错误是什么意思
只看楼主 加入收藏
gwlgqx
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-6-2
收藏
 问题点数:0 回复次数:6 
这此错误是什么意思

java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at _liuyuanban__jsp._jspService(/liuyuanban.jsp:31)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:311)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:595)
下面是自己写的代码:
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,java.io.*,java.util.*" %>

<html>
<head>
<title>简易留言板</title>
</head>
<body>

<center>

<script language=javascript>
<!--

function tijiao()
{
if(checkbox.titletext.value=="")
{
window.alert("你还没有写你要发表的留言的主题");
checkbox.titletext.focus();
return;
}
else if(checkbox.textarea.value=="")
{
window.alert("你还没有写任何留言");
checkbox.textarea.focus();
return;
}
else
{
<%
int photoid=Integer.parseInt(request.getParameter("face"));
String title=request.getParameter("titletext");
String nr=request.getParameter("textarea");
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=liuyuangban";
String user="sa";
String pw="";

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn= DriverManager.getConnection(url,user,pw);
Statement stmt=conn.createStatement();
String sql="insert into liuyuan(title,text,photoid) values(\'"+title+"\',\'"+nr+"\',"+photoid+")";
stmt.executeUpdate(sql);
out.print("留言成功");
%>


}

}

-->
</script>

<form action="liulan.jsp" method="post" name=checkbox >
<table width="800" border="0" align="left" bgcolor="#fedf87" cellspacing="0" cellpadding="0" >
<tr>
<td width="100%" align="center" ><font size="5" color="#FFFFFF"><b><u>填写留言</u></b></font></td>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#FCFCFC">发表主题</td>
</tr>
<tr>
<td width="100%" bgcolor="#FCFCFC"><input name="titletext" type="text" size="60"></td>
</tr >
<tr><td width="100%" bgcolor="#FCFCFC">内容:</td>
</tr>
<tr><td width="100%" bgcolor="#FCFCFC" align=left><textarea name="textarea" cols=60 rows=10></textarea></td>
</tr>
<tr>
<td width="100%" bgcolor="#FCFCFC">
<% for(int i=1;i<=10;i++){%>
<input name="face" type="radio" value=<%=i%>> <img src="image/<%=i%>.gif" >
<%}%>
</td>
</tr>

<tr><td ><input type=button value="提交" onclick=tijiao();>&nbsp;&nbsp;<input name="reset" type="reset" value="取消"></td></tr>

</table>
</form>
</center>

</body>
</html>

搜索更多相关主题的帖子: null 
2007-09-17 10:27
evollock
Rank: 1
等 级:新手上路
帖 子:67
专家分:0
注 册:2007-7-4
收藏
得分:0 
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)

.说明你某个值转换成了不对的格式

int photoid=Integer.parseInt(request.getParameter("face"));//貌似是着句,LX继续
2007-09-17 10:36
susan001983
Rank: 1
等 级:新手上路
威 望:1
帖 子:125
专家分:0
注 册:2007-7-25
收藏
得分:0 
int photoid=Integer.parseInt(request.getParameter("face"));

这句有问题吧。

空指针异常。

Integer photoid=Integer.parseInt(request.getParameter("face"));
这样转吧。

2007-09-17 11:13
Gramary
Rank: 4
等 级:贵宾
威 望:13
帖 子:769
专家分:0
注 册:2007-7-9
收藏
得分:0 

我估计是因为`
request.getParameter("face");
这个本身是一个null值`
表示根本没有获得值```所以转变数据类型就出现错误了```
我建议先
int photoid = 0;
String id = request.getParameter("face");
if(id != null && !"".equals(id ))
{
photoid = Integer.parseInt(id);
}


学编程不能急,要慢慢来。
2007-09-17 11:41
gwlgqx
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-6-2
收藏
得分:0 
试过了,不行呀
2007-09-17 12:07
netstriker
Rank: 1
等 级:新手上路
威 望:1
帖 子:257
专家分:0
注 册:2007-3-24
收藏
得分:0 

严重同意Gramary所说的~

int photoid=Integer.parseInt(request.getParameter("face"));
String title=request.getParameter("titletext");
String nr=request.getParameter("textarea");

这几句很有问题,因为当页面第一次加载时,face,titletext,textarea的值根本就是null
所以当执行到上面几句时,肯定会出错.应该在这几句前加上检查语句.
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,java.io.*,java.util.*" %>

<html>
<head>
<title>简易留言板</title>
</head>
<body>

<center>

<script language=javascript>
<!--

function tijiao()
{
if(checkbox.titletext.value=="")
{
window.alert("你还没有写你要发表的留言的主题");
checkbox.titletext.focus();
return;
}
else if(checkbox.textarea.value=="")
{
window.alert("你还没有写任何留言");
checkbox.textarea.focus();
return;
}
else
{
<%
if(request.getParameter("face")!=null && request.getParameter("titletext")!=null && request.getParameter("titletext")!=null && request.getParameter("textarea")!=null) ---->>要它们全部不能为空~
{
int photoid=Integer.parseInt(request.getParameter("face"));
String title=request.getParameter("titletext");
String nr=request.getParameter("textarea");
}
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=liuyuangban";
String user="sa";
String pw="";

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn= DriverManager.getConnection(url,user,pw);
Statement stmt=conn.createStatement();
String sql="insert into liuyuan(title,text,photoid) values(\'"+title+"\',\'"+nr+"\',"+photoid+")";
stmt.executeUpdate(sql);
out.print("留言成功");
%>


}

}

-->
</script>


<form action="liulan.jsp" method="post" name=checkbox >
<table width="800" border="0" align="left" bgcolor="#fedf87" cellspacing="0" cellpadding="0" >
<tr>
<td width="100%" align="center" ><font size="5" color="#FFFFFF"><b><u>填写留言</u></b></font></td>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#FCFCFC">发表主题</td>
</tr>
<tr>
<td width="100%" bgcolor="#FCFCFC"><input name="titletext" type="text" size="60"></td>
</tr >
<tr><td width="100%" bgcolor="#FCFCFC">内容:</td>
</tr>
<tr><td width="100%" bgcolor="#FCFCFC" align=left><textarea name="textarea" cols=60 rows=10></textarea></td>
</tr>
<tr>
<td width="100%" bgcolor="#FCFCFC">
<% for(int i=1;i<=10;i++){%>
<input name="face" type="radio" value=<%=i%>> <img src="image/<%=i%>.gif" >
<%}%>
</td>
</tr>

<tr><td ><input type=button value="提交" onclick=tijiao();>&nbsp;&nbsp;<input name="reset" type="reset" value="取消"></td></tr>

</table>
</form>
</center>

</body>
</html>

2007-09-17 13:32
blackboy
Rank: 1
等 级:新手上路
威 望:1
帖 子:34
专家分:0
注 册:2007-10-21
收藏
得分:0 
int photoid=Integer.parseInt((String)request.getParameter("face"))应该就好用了
2007-10-25 18:04
快速回复:这此错误是什么意思
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016150 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved