My controller is like :
public ModelAndView postMethod(
@ModelAttribute("attribute") ) throws Exception {
ModelAndView mav = new ModelAndView("jsp");
Date todayDate = new Date();
Session session = null;
Transaction transaction = null;
if (issue_vendor.getOutward_item_code1() != null) {
transaction = session.beginTransaction();
session = sessionFactory.openSession();
Query query = session.createQuery("FROM stock_register_dto where item_code=:code order by date desc");
query.setInteger("code", issue_vendor.getOutward_item_code1());
query.setMaxResults(1);
List<stock_register_dto> list = query.list();
System.out.println("result: " + list);
for (stock_register_dto check : list) {
Integer code1 = check.getItem_code();
Integer stock1 = check.getStock();
if (code1 == issue_vendor.getOutward_item_code1() && stock1 >= issue_vendor.getQuantity_issued1()) {
this.master_service.saveRequirement(dto);
session.flush();
session.clear();
}
}
}
if (issue_vendor.getOutward_item_code2() != null) {
transaction = session.beginTransaction();
session = sessionFactory.openSession();
Query query = session.createQuery("FROM stock_register_dto where item_code=:code order by date desc");
query.setInteger("code", issue_vendor.getOutward_item_code2());
query.setMaxResults(1);
List<stock_register_dto> list = query.list();
System.out.println("result: " + list);
for (stock_register_dto check : list) {
Integer code1 = check.getItem_code();
Integer stock1 = check.getStock();
if (code1 == issue_vendor.getOutward_item_code2() && stock1 >= issue_vendor.getQuantity_issued2()) {
this.master_service.saveRequirement(dto);
session.flush();
session.clear();
}
}
}
return mav;
}
When i am using this controller, i got this error ..
HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
type Exception report
message Request processing failed; nested exception is java.lang.NullPointerException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) javax.servlet.http.HttpServlet.service(HttpServlet.java:650) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException com.stock_issuance.controller.Stock_issuance_controller.saveStock4(Stock_issuance_controller.java:118) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) javax.servlet.http.HttpServlet.service(HttpServlet.java:650) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.68 logs.