好奇怪的问题啊,关于java.lang.NullPointerException异常问题]求助

CNSDYT 2004-12-20 03:00:45
我在jsp里调试下面的页面,要是按住F5不动快速刷新,就会抛出异常java.lang.NullPointerException,如果把
IndexXx ix = new IndexXx();
CssMgr cm = new CssMgr();
xxinfo xx = new xxinfo();
String xxtitle = "";
String xxtjtime = "";
String xxid = "";
int xxsort = 0;
Vector v = new Vector();
这段代码去掉就不会抛出异常,只有加上才会抛出异常,这是什么怪问题阿,又遇到过的吗,困扰很久了,请大家帮我解决一下,不胜感激
list.jsp
<%@ page language="java" contentType="text/html;charset=GBK"%>
<%@ page import="java.io.*" %>
<%@ page import="javaclass.javabean.xxinfo.xxinfostruct" %>
<%@ page import="java.util.*,java.lang.*" %>
<%@ page import="javaclass.javabean.xxinfo.*" %>
<%@ page import="javaclass.javabean.purview.purview" %>

<%


IndexXx ix = new IndexXx();
CssMgr cm = new CssMgr();
xxinfo xx = new xxinfo();
String xxtitle = "";
String xxtjtime = "";
String xxid = "";
int xxsort = 0;
Vector v = new Vector();
try{
ArrayList m1 = new ArrayList();
purview pru = new purview();
ArrayList al = pru.getAllLMName();

}catch(Exception e){
out.println(e.toString());
}
%>

purview.java
public ArrayList getAllLMName()
{
String sql = "select * from rwm_lm order by no";
String lm_name_no="";
ArrayList al = new ArrayList();
try{
RS= Stmt.executeQuery(sql);
while(RS.next())
{
lm_name_no = RS.getString("lanmu")+"|"+RS.getInt("no");
al.add(lm_name_no);
}
}catch(SQLException e)
{
System.out.print(e.getMessage());
}
return al;
}
...全文
275 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
CNSDYT 2004-12-22
  • 打赏
  • 举报
回复
问题没有解决,唉,但我还是要谢谢大家的帮助
CNSDYT 2004-12-22
  • 打赏
  • 举报
回复
alYN = pru.getAllLM(Integer.parseInt(cnlife_user_userid));
异常就是上面调用抛出的异常,代码我改了
public ArrayList getAllLM(int userid)
{
String sql = "select user_lm from rwm where userid = "+userid+"";

ArrayList al = new ArrayList();
purview pru = new purview();
try{
RS= Stmt.executeQuery(sql);
while(RS.next())
{

pru.setLmTag(RS.getInt("user_lm"));
pru.setLmName(pru.getLMname(RS.getInt("user_lm")));
al.add(pru);
}
}catch(SQLException e)
{
System.out.print(e.getMessage());
}
return al;
}
贷还是没有解决
awaysrain 2004-12-22
  • 打赏
  • 举报
回复
你单步调试以下就知道哪里抛出的异常了,自己动手吧
CNSDYT 2004-12-22
  • 打赏
  • 举报
回复
又遇到的朋友帮我解决一下吧
CNSDYT 2004-12-22
  • 打赏
  • 举报
回复
我在另一个页面又遇到了同样的问题,代码如下:
jsp文件
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javaclass.myJava.str.myString" %>
<%@ page import="javaclass.javabean.xxinfo.xxinfostruct" %>
<%@ page import="javaclass.javabean.xxinfo.*" %>
<%@ page import="javaclass.javabean.purview.purview" %>
<%!

purview pru = new purview();
ArrayList alYN = new ArrayList();
int no;//栏目标识
int YN7 = 0;//删除权限
String QX_a = "";//根据userid,user_lm传出本栏目权限
%>
<%

String dt = request.getParameter("delTag2");

String cnlife_user_userid = (String)session.getAttribute("cnlife_logon_userid");
if(cnlife_user_userid == null || cnlife_user_userid.length()<8){
response.sendRedirect("../../logon.jsp");
}

try{
no = Integer.parseInt(request.getParameter("lmid"));
}catch(Exception e)
{
no = 10000;
}

QX_a = pru.getUserQx(Integer.parseInt(cnlife_user_userid),no);
if(QX_a.length()>0)
{
String QX_1="";
switch(Integer.parseInt(dt))
{ case 0:
QX_1 = QX_a.substring(2,3);
break;
case 1:
QX_1 = QX_a.substring(0,1);
break;
case 2:
QX_1 = QX_a.substring(1,2);
break;
default:
QX_1 = QX_a.substring(3,4);
break;
}

YN7=pru.passYN(QX_1,4);
}

%>
<%

alYN = pru.getAllLM(Integer.parseInt(cnlife_user_userid));//得到该用户是否是管理员
//好想就是上面这一举抛出的异常


%>

javabean里的代码,其中一个方法
public ArrayList getAllLM(int userid)
{
String sql = "select user_lm from rwm where userid = "+userid+"";
int user_lm;

ArrayList al = new ArrayList();
try{
RS= Stmt.executeQuery(sql);
while(RS.next())
{
purview pru = new purview();
pru.setLmTag(RS.getInt("user_lm"));
pru.setLmName(pru.getLMname(RS.getInt("user_lm")));
al.add(pru);
}
}catch(SQLException e)
{
System.out.print(e.getMessage());
}
return al;
}
CNSDYT 2004-12-21
  • 打赏
  • 举报
回复
阿,那怎么办啊,需要在程序里怎么修改阿
cxjd 2004-12-20
  • 打赏
  • 举报
回复
这种情况一般是由变量未初始化就调用,或者往不能为null值的地方放null值引起的,
例如:在一文件中声明了变量String s1;未加初始化就在第二文件中调用方法String[]s2=s1.split(",");这样就会出现。
第二点:例如往一Hashtable 插入空值ht.put(null,null),

我觉得应该好好检查一下你前面声明的那三个类文件(IndexXx,CssMgr,xxinfo)
有可能是由类变量的相互调用产生的。由于程序的执行速度,有可能一类内的变量还没初始化,在别的地方就调用之
cxjd 2004-12-20
  • 打赏
  • 举报
回复
这种情况一般是由变量未初始化就调用,或者往不能为null值的地方放null值引起的,
例如:在一文件中声明了变量String s1;未加初始化就在第二文件中调用方法String[]s2=s1.split(",");这样就会出现。
第二点:例如往一Hashtable 插入空值ht.put(null,null),

我觉得应该好好检查一下你前面生命的那三个类文件(IndexXx,CssMgr,xxinfo)
有可能是由类变量的相互调用产生的。由于程序的执行速度,有可能以类内的变量还没初始化,在别的地方就调用
junyi2003 2004-12-20
  • 打赏
  • 举报
回复
我觉得和你的WEB服务器有关系。是开发版嘛?
loverisyour 2004-12-20
  • 打赏
  • 举报
回复
了解一下
CNSDYT 2004-12-20
  • 打赏
  • 举报
回复
为何慢慢的刷新没有什么问题,而在快速刷新时会出现错误呢,使程序写的不规范还是服务器,我觉得好像是程序有问题
CNSDYT 2004-12-20
  • 打赏
  • 举报
回复
这种错误一般是有什么引起的阿?
lijunjiejava 2004-12-20
  • 打赏
  • 举报
回复
关注中/
junyi2003 2004-12-20
  • 打赏
  • 举报
回复
或者你打开的连接数过多了。你web licence对连接有限制的
IndexXx ix = new IndexXx();
CssMgr cm = new CssMgr();
......
是不是打开了新的HTTP连接?
junyi2003 2004-12-20
  • 打赏
  • 举报
回复
我觉得应该一直抛出这样一个错误的,而不是按住不停刷新才出现的。请IE Cache再试
华生豆 2004-12-20
  • 打赏
  • 举报
回复
list.jsp
<%@ page language="java" contentType="text/html;charset=GBK"%>
<%@ page import="java.io.*" %>
<%@ page import="javaclass.javabean.xxinfo.xxinfostruct" %>
<%@ page import="java.util.*,java.lang.*" %>
<%@ page import="javaclass.javabean.xxinfo.*" %>
<%@ page import="javaclass.javabean.purview.purview" %>

<%!
IndexXx ix = new IndexXx();
CssMgr cm = new CssMgr();
xxinfo xx = new xxinfo();
String xxtitle = "";
String xxtjtime = "";
String xxid = "";
int xxsort = 0;
Vector v = new Vector();
%>
<%
try{
ArrayList m1 = new ArrayList();
purview pru = new purview();
ArrayList al = pru.getAllLMName();

}catch(Exception e){
out.println(e.toString());
}
%>

试一下~~~
CNSDYT 2004-12-20
  • 打赏
  • 举报
回复
getAllLMName()是写在一个类里的,purview是一个javabean
BillyW 2004-12-20
  • 打赏
  • 举报
回复
<% ----> <%!

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧