日期:2014-05-18  浏览次数:20729 次

又遇见一个空指针问题,感觉报错的代码不可能有问题啊!大家进来看看!
2007-4-5   22:45:34   org.apache.catalina.core.StandardWrapperValve   invoke
严重:   Servlet.service()   for   servlet   jsp   threw   exception
java.lang.NullPointerException
at   org.apache.jsp.UserAdmin.adddata.save_jsp._jspService(save_jsp.java:158)---系统报错代码行
at   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at   org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)
at   org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)
at   org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
at   org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
at   org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
at   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at   java.lang.Thread.run(Thread.java:595)

具体代码如下(太多只能贴一小部分):
String   xxfl_str= " ";
String   xilei_str= " ";
String   hangye=request.getParameter( "classid ");//classid是必选菜单值,变量hangye不可能会空的,为什么系统还会认为下一句有问题呢?
if   (hangye.equals( "6 ")){   ---系统认为此句有问题,
xxfl_str= "65 ";
xilei_str= "63,64,65,67,71,72,414, ";
}
请dx们指教!

------解决方案--------------------
String hangye=request.getParameter( "classid ");
System.out.println(hangye);
看看hangye是否为空。

想要避免这个问题可以这样写,
if (( "6 ").equal(shangye)){
}
------解决方案--------------------
把“hangye”这个变量的值打印出来就知道对错了
------解决方案--------------------
改成 String hangye=(String)request.getParameter( "classid ");试一下,
再不行就把这个变量在打印输出看是不是空
------解决方案--------------------
if(hangye!=null){
if (hangye.equals( "6 ")){
xxfl_str= "65 ";
xilei_str= "63,64,65,67,71,72,414, ";
}
}
这样写试试
------解决方案--------------------
classid是必选菜单 是不是没设值呀!注意一下,看看是不是
------解决方案--------------------
if (( "6 ").equal(shangye)){
}
如果不报错就是shangye为空

其实eclipse可以调试jsp的啊