在线等候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";
...全文
67 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
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)
类型好像报错啊

81,122

社区成员

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

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