问题描述
- 求解决,总是报NullPointerException
-
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
IncomeTypeService itservice = new IncomeTypeServiceImpl();
HttpSession session=request.getSession();
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String incomeTypeName=request.getParameter("incomeTypeName");
int incomeTypeNo= Integer.parseInt(request.getParameter("incomeTypeNo"));
System.out.println(incomeTypeNo+":"+incomeTypeName);
try{
IncomeType incomeType = itservice.findIncomeTypeByIncomeTypeName(incomeTypeName);
//这里可以输出数据
System.out.println(incomeTypeNo+":"+incomeTypeName);//NullPointerException incomeType.setIncomeTypeName(incomeTypeName); incomeType.setIncomeTypeNo(incomeTypeNo); itservice.updateIncomeType(incomeType);
2015-12-12 23:41:12 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [UpdateIncomeTypeServlet] in context with path [/financialManager] threw exception
java.lang.NullPointerException
at com.dyh.familyfinancialmanager.servlet.incometype.UpdateIncomeTypeServlet.doPost(UpdateIncomeTypeServlet.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at com.dyh.familyfinancialmanager.filter.EncodeFilter.doFilter(EncodeFilter.java:27)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:619)求解决啊!!!
解决方案
检查下你的incomeType是否为空
解决方案二:
值没有传过来吧。能不能打印一下
解决方案三:
IncomeTYpename是否为空?数据类型是什么?
解决方案四:
int incomeTypeNo= Integer.parseInt(request.getParameter("incomeTypeNo"));
String incomeTypeName=request.getParameter("incomeTypeName");
System.out.println(incomeTypeNo+":"+incomeTypeName);
111:工资
解决方案五:
空指针,很简单,说明哪个指针变量是空的,问题出在你给变量赋值的地方。好好看,这是最简也是培养好习惯的地方。
解决方案六:
at com.dyh.familyfinancialmanager.filter.EncodeFilter.doFilter(EncodeFilter.java:27)
看一下你filter有没有什么限制