在线等候nullpointExecpion

xuefeifangpei 2003-04-08 12:30:33
我有如下语句在判断是都用了xx!=null进行判断,但是仍然出错究竟时什么原因

tousu_end_date1=request.getParameter("tousu_end_date");
if (tousu_end_date1 ==null)
tousu_end_date1 ="";
depart1=request.getParameter("depart");
if (depart1 ==null)
depart1 ="";
details1=request.getParameter("details");
if (details1 ==null)
details1 ="";
handle1=request.getParameter("handle");
if (handle1 ==null)
handle1 ="";
person1=request.getParameter("person");
if (person1 ==null)
person1 ="";
tousu_class1=request.getParameter("tousu_class");
if (tousu_class1 ==null)
tousu_class1 ="";
strSQL="select * FROM data where ";

if(!tousu_class1.trim().equals(""))
strSQL=strSQL+" and tousu_class like '%"+tousu_class1+"%' ";
if(!depart1.trim().equals("") )
strSQL=strSQL+" depart = '"+depart1+"' ";
if( !handle1.trim().equals("") )
strSQL=strSQL+" and handle = '"+handle1+"' ";
if( !details1.trim().equals("") )
strSQL=strSQL+" and details like '%"+details1+"%' ";
if( !person1.trim().equals("") )
strSQL=strSQL+" and person = '"+person1+"' ";
if(!tousu_start_date1.trim().equals("") && !tousu_end_date1.trim().equals("") )
strSQL=strSQL+" and tousu_date between #"+tousu_start_date1+"# and #"+tousu_end_date1+"# order by tousu_date desc";
...全文
14 点赞 收藏 16
写回复
16 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
kreven 2003-04-08
同意调试
回复
kyouyouCafe 2003-04-08
后半部分好象有问题.
尝试:
String str = tousu_class1;
if(str != null && str.trim().length()>0){
//deal with

}
后面也象前面那样处理...

回复
flashroom 2003-04-08
用==判断试试
回复
xuefeifangpei 2003-04-08
谢谢!我这样好了
tousu_start_date1=request.getParameter("tousu_start_date");
if (tousu_start_date1==null)
tousu_start_date1="";
tousu_end_date1=request.getParameter("tousu_end_date");
if (tousu_end_date1 ==null)
tousu_end_date1="";
depart1=request.getParameter("depart");
if (depart1==null)
depart1="";
details1=request.getParameter("details");
if (details1==null)
details1="";
handle1=request.getParameter("handle");
if (handle1==null)
handle1="";
person1=request.getParameter("person");
if (person1==null)
person1="";
tousu_class1=request.getParameter("tousu_class");
if (tousu_class1==null)
tousu_class1="";
strSQL="select * FROM data where ";
if(tousu_class1!=null && tousu_class1.trim().length()>0)
strSQL=strSQL+" tousu_class like '%"+tousu_class1+"%' and ";

if(depart1!=null && depart1.trim().length()>0 )
strSQL=strSQL+" depart = '"+depart1+"' and ";

if(handle1!=null && handle1.trim().length()>0 )
strSQL=strSQL+" handle = '"+handle1+"' and ";

if(details1!=null && details1.trim().length()>0 )
strSQL=strSQL+" details like '%"+details1+"%' and ";

if(person1!=null && person1.trim().length()>0 )
strSQL=strSQL+" person = '"+person1+"' and ";


if(tousu_start_date1!=null && tousu_start_date1.trim().length()>0 && tousu_end_date1!=null && tousu_end_date1.trim().length()>0 )
strSQL=strSQL+" tousu_date between #"+tousu_start_date1+"# and #"+tousu_end_date1+"# order by tousu_date desc";
回复
nbm0 2003-04-08
请这样;

if(str != null && str.length() > 0)
{
do what you want to do
}

上面语句中,str != null 先判断是否为空,str.length() > 0再判断长度是否为0
都不成立,则str有内容!
回复
dalyyy 2003-04-08
你先把strSQL print 出来看一下就知道strSQL对不对了,如果strSQL没问题的话就是别的代码的问题了
回复
dybine 2003-04-08
这段代码没有错,错误可能在你别的代码上
回复
niko7 2003-04-08
你先用个简单点的页面好好调一下吧。
回复
kyouyouCafe 2003-04-08
当然了.
你要先确定String 类型的对象不为空.
然后再判断长度是否为零.
回复
teva 2003-04-08
看异常类型
这样的问题不需要怎么琢磨源码
回复
kyouyouCafe 2003-04-08
depart1.trim().length()>0 中没加"AND".
下断点调试,看哪儿有错?
回复
vick 2003-04-08
对空对象进行了操作(比如转换操作等等,string 类型空串的trim();)
回复
xuefeifangpei 2003-04-08
查depart1能够,但是查其他的就报错不知道什么原因哦??
回复
xuefeifangpei 2003-04-08
还是报nullpoint错
tousu_start_date1=request.getParameter("tousu_start_date");
if (tousu_start_date1==null)
tousu_start_date1="";
tousu_end_date1=request.getParameter("tousu_end_date");
if (tousu_end_date1 ==null)
tousu_end_date1="";
depart1=request.getParameter("depart");
if (depart1==null)
depart1="";
details1=request.getParameter("details");
if (details1==null)
details1="";
handle1=request.getParameter("handle");
if (handle1==null)
handle1="";
person1=request.getParameter("person");
if (person1==null)
person1="";
tousu_class1=request.getParameter("tousu_class");
if (tousu_class1==null)
tousu_class1="";
strSQL="select * FROM data where ";
if(tousu_class1.trim().length()>0)
strSQL=strSQL+" and tousu_class like '%"+tousu_class1+"%' ";

if(depart1.trim().length()>0 )
strSQL=strSQL+" depart = '"+depart1+"' ";

if(handle1.trim().length()>0 )
strSQL=strSQL+" and handle = '"+handle1+"' ";

if(details1.trim().length()>0 )
strSQL=strSQL+" and details like '%"+details1+"%' ";

if(person1.trim().length()>0 )
strSQL=strSQL+" and person = '"+person1+"' ";


if(tousu_start_date1.trim().length()>0 && tousu_end_date1.trim().length()>0 )
strSQL=strSQL+" and tousu_date between #"+tousu_start_date1+"# and #"+tousu_end_date1+"# order by tousu_date desc";
回复
kyouyouCafe 2003-04-08

tousu_class1.trim().length()>0
不是length.
回复
xuefeifangpei 2003-04-08
..\work\localhost\tousu\_0002fsql_0005fok_0002ejspsql_0005fok_jsp_84.java:186: Attempt to reference method length in class java.lang.String as an instance variable.
if(tousu_class1.trim().length>0)
类型好像报错啊
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-04-08 12:30
社区公告
暂无公告