空指针

问题描述

源码:packagecom.intern.servlet;importjava.io.IOException;importjava.io.PrintWriter;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importcom.intern.Page.Page;importcom.intern.entity.PracticeResultInfo;importcom.intern.entity.TeacherInfo;importcom.intern.jbdc.PracticeResultInfoDAO;importcom.sun.org.apache.regexp.internal.RESyntaxException;publicclassPracticeServletextendsHttpServlet{PracticeResultInfoDAOpraDAO=newPracticeResultInfoDAO();publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{PracticeResultInfopra=newPracticeResultInfo();request.setCharacterEncoding("utf-8");Stringoper=request.getParameter("oper");if(oper.equals("getAll")){//实现查询所有学生数据List<PracticeResultInfo>data1=praDAO.getAll();//将数据放到request中,转给JSP显示request.setAttribute("data1",data1);//转发request.getRequestDispatcher("/pra_manager.jsp").forward(request,response);}if(oper.equals("getOne")){StringstrId=request.getParameter("id");intid=Integer.parseInt(strId);PracticeResultInfote=praDAO.getById(id);//将数据放到requet中,转给JSP显示request.setAttribute("te",te);//转发request.getRequestDispatcher("/pra_show.jsp").forward(request,response);}//添加用户信息if(oper.equals("add")){PracticeResultInfouserAd=newPracticeResultInfo();userAd.setStuId(Integer.getInteger(request.getParameter("stuId")));userAd.setStuName(request.getParameter("stuName"));userAd.setStuNo(request.getParameter("stuNo"));userAd.setStuClass(request.getParameter("stuClass"));userAd.setTeaName(request.getParameter("teaName"));userAd.setPrTitle(request.getParameter("praTitle"));userAd.setPrContent(request.getParameter("prContent"));userAd.setPrFile(request.getParameter("prFile"));request.setAttribute("userAd",userAd);if(praDAO.add(userAd)){request.setAttribute("msg","添加实习生记录成功!");}else{request.setAttribute("msg","添加实习生记录失败!");}request.getRequestDispatcher("/pra_add.jsp").forward(request,response);}//删除用户信息if(oper.equals("delete")){StringusId=request.getParameter("id");intid=Integer.parseInt(usId);if(praDAO.delete(id)){request.setAttribute("msg","删除实习生记录成功!");}else{request.setAttribute("msg","删除实习生记录失败!");}request.getRequestDispatcher("/PracticeServlet?oper=getByPage").forward(request,response);}//修改用户信息if(oper.equals("get")){StringusId=request.getParameter("id");intid=Integer.parseInt(usId);PracticeResultInfot=praDAO.getById(id);request.setAttribute("t",t);request.getRequestDispatcher("/pra_update.jsp").forward(request,response);}if(oper.equals("update")){pra.setStuId(Integer.parseInt(request.getParameter("stuId")));pra.setStuName(request.getParameter("stuName"));pra.setStuNo(request.getParameter("stuNo"));pra.setStuClass(request.getParameter("stuClass"));pra.setTeaName(request.getParameter("teaName"));pra.setPrTitle(request.getParameter("prTitle"));pra.setPrContent(request.getParameter("prContent"));pra.setPrFile(request.getParameter("prFile"));if(praDAO.update(pra)){request.setAttribute("msg","修改实习生记录成功!");request.getRequestDispatcher("/PracticeServlet?oper=getByPage").forward(request,response);}else{request.setAttribute("msg","修改实习生记录失败!");request.getRequestDispatcher("/PracticeServlet?oper=getByPage").forward(request,response);}}//分页//按页进行搜所if(oper.equals("getByPage")){//默认查询所有数据Stringsql="select*frompracticeResultinfoorderbyid";//定义数据查询集合List<PracticeResultInfo>allData=null;//获取查询的参数值//获取关键字的名称和值StringkeywordName=request.getParameter("keywordName");StringkeywordValue=request.getParameter("keywordValue");StringorderBy=request.getParameter("orderBy");//如果查询参数不为空,从新构建sql语句if(keywordName!=null&&keywordValue!=null){sql="select*frompracticeResultinfowhere"+keywordName+"like'%"+keywordValue+"%'";//确定排序规则if(orderBy.equals("0")){sql=sql+"orderbyid";}else{sql=sql+"orderby"+orderBy;}//将查询数据放到Session中保存request.getSession().setAttribute("sql",sql);}//判断Session中存在查询条件,进行分页if(request.getSession().getAttribute("sql")!=null){sql=(String)request.getSession().getAttribute("sql");}//SQL确定后进行分页查询allData=praDAO.getBySQL(sql);//判断是否含有页码信息StringcurrentPageStr=request.getParameter("pageCode");intcurrentPage=1;//如果有页码,则获取页码if(currentPageStr!=null){currentPage=Integer.parseInt(currentPageStr);}//创建Page对象进行分页Pagep=newPage(allData.size(),currentPage,10);//得到页面数据Listdata=praDAO.getByPage(p,allData);//将获得的当前页面数据保存到request中request.setAttribute("data",data);//将分页信息保存到request中request.setAttribute("page",p);//转向request.getRequestDispatcher("/pra_manager.jsp").forward(request,response);}}}错误提示:严重:Servlet.service()forservlet[PracticeServlet]incontextwithpath[/intern]threwexception[java.lang.NullPointerException]withrootcausejava.lang.NullPointerExceptionatorg.apache.jsp.pra_005fmanager_jsp._jspService(pra_005fmanager_jsp.java:124)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:722)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:722)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)atorg.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)atorg.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)atorg.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)atorg.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)atcom.intern.servlet.PracticeServlet.doPost(PracticeServlet.java:151)atcom.intern.servlet.PracticeServlet.doGet(PracticeServlet.java:24)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:621)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:722)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)atorg.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)atorg.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)atorg.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)atorg.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)atorg.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1805)atjava.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)atjava.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)atjava.lang.Thread.run(Thread.java:619)

解决方案

解决方案二:
你至少把空指针的那一行标注出来啊。!
解决方案三:
根据置顶帖,是不是得直接给你删了。你这像是来问问题的吗。。
解决方案四:
楼主打断点可以直接看看哪一行出错了,找到空指针位置,问题也就解决75%了。空指针也不是很难处理的问题,一般就是对象为空或没有初始化,检查下就是了。
解决方案五:
你打断点,自己DEBUG,光看,看不出来
解决方案六:
楼主啊!错误自己用很显眼的颜色弄出来啊!
解决方案七:
都是代码,看晕了,建议楼主下次要问时应该将出错点指出
解决方案八:
找到jsp对应的class/java,看124行代码
解决方案九:
atcom.intern.servlet.PracticeServlet.doPost(PracticeServlet.java:151)atcom.intern.servlet.PracticeServlet.doGet(PracticeServlet.java:24)错误给你标识出来了,你自己跟吧。。贴个代码也不贴行数,懒得数行数了

时间: 2024-10-23 14:49:28

空指针的相关文章

jdbcdaosupport-Spring mvc 空指针错误

问题描述 Spring mvc 空指针错误 LoginController @Controller public class LoginController { @RequestMapping("test") public void login() { LoginServiceImp loginService = new LoginServiceImp(); loginService.loadUserInfo(); } } LoginServiceImp public class Lo

tigase 消息推送-tigase-server运行报空指针

问题描述 tigase-server运行报空指针 如题通过下载最新版的tigase-server 7.0.1.exe 解压jar 运行安装...启动时报错通过Pandion客户端无法连接,求大神指点!主要是做消息推送 !

图片-Eclipse编译Java文件出现空指针错误,求大神指教如何改正

问题描述 Eclipse编译Java文件出现空指针错误,求大神指教如何改正 另外出现错误的代码 主函数 public static void main(String[] args) { Login login = new Login(RELOAD); login.setVisible(true); } public Login() { super(); initialize(); } public Login(boolean reload) { super(); initialize(); ne

界面跳转-intent.getExtras();报空指针

问题描述 intent.getExtras();报空指针 错误的重点是:**把最后Activity接收Activity1传来的数据代码,放在一个按钮中就完全正确,但是要是放在onCreate中,就崩溃报空指针** 程序先是Activity跳到Activity1,然后从Activity1中获取字符串传递回Activity中. 下面是Activity跳转到Activity1的代码: Intent intent=new Intent(); intent.setClass(MainActivity.th

andiord-程序运行时强制关闭,可能为空指针

问题描述 程序运行时强制关闭,可能为空指针 日志:java.lang.RuntimeException: Unable to start activity ComponentInfo{pcAlarm.pack/pcAlarm.pack.PCAlarmActivity}: java.lang.NumberFormatException: 空指针错误,可能在private void readSaveAlarm(){ SharedPreferences sp =getContext().getShar

自定义对象 xfire-用spring整合xfire时传递自定义类型的对象时报空指针错误

问题描述 用spring整合xfire时传递自定义类型的对象时报空指针错误 Exception in thread ""main"" org.codehaus.xfire.fault.XFireFault: Fault: java.lang.NullPointerException at org.codehaus.xfire.fault.XFireFault.createFault(XFireFault.java:89) at org.codehaus.xfire.

C/C++中利用空指针简化代码提高效率

这里的写法,可以避免使用 for 循环,减少栈空间内存的使用和减少运行时的计算开销! #include <iostream>#include <string>using namespace std;void print_char(char* array[]);//函数原形声明void main(void){ char* test[]={"abc","cde","fgh",NULL};//这里添加一个NULL,表示不指向任何

空指针(NULL,0),野指针,void*的讲解

一:野指针 "野指针"不是NULL指针,是指向"垃圾"内存的指针. "野指针"的成因主要有两种: (1)指针变量没有被初始化.任何指针变量刚被创建时不会自动成为NULL指针,它的缺省值是随机的,它会乱指一气.所以,指针变量在创建的同时应当被初始化,要么将指针设置为NULL,要么让它指向合法的内存.例如      char *p = NULL;      char *str = (char *) malloc(100); (2)指针p被free或者

jsp 页面这样,然后服务器抛出空指针错误

问题描述 jsp 页面这样,然后服务器抛出空指针错误 <%@ page contentType = "text/html;charset= gbb2312" %> <%@ page language = "java" pageEncoding = "gb2312" %> <%@ page import = "java.util.*" %> <%@ page import = "

exception-安卓空指针 异常 请问 怎么回事 小弟刚开始写安卓代码

问题描述 安卓空指针 异常 请问 怎么回事 小弟刚开始写安卓代码 03-30 12:16:38.625: E/AndroidRuntime(19941): FATAL EXCEPTION: main 03-30 12:16:38.625: E/AndroidRuntime(19941): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.voldian/com.voldian.voldian.shangc