chqhroqkfwk
72
2018-02-22 10:26:31 작성 2018-02-22 10:28:09 수정됨
6
828

autowired된 객체가 특정 메서드 안에만 들어가면 nullpoint 됩니다.


컨트롤러

@Controller

@RequestMapping(value = "sns/*")

public class SNSController {

@Autowired

HttpSession session;

@Autowired

SNSService nservice;

@RequestMapping(value = "/postForm", method = RequestMethod.POST)

public ModelAndView postForm(@RequestParam("calNum") String calnum) {

ModelAndView mav = new ModelAndView();

mav.addObject("calnum", calnum);

mav.setViewName("postForm");

nservice.test(); //이부분의 test();는 잘 실행됨

return mav;

}

@RequestMapping(value = "/post", method = RequestMethod.POST)

public ModelAndView post(@ModelAttribute("tl") Timeline timeline) {

timeline.setT_cc_code(session.getAttribute("code").toString());

System.out.println("테스트 : "+timeline.getT_content());

nservice.test(); //이부분을 주석처리하면 잘 실행됨 주석처리 하지 않으면 nullpoint

ModelAndView mav = new ModelAndView();

mav.setViewName("postresult");

return mav;

}

에러 로그

심각: Servlet.service() for servlet [appServlet] in context with path [/www] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause

java.lang.NullPointerException

at com.chicknest.www.SNSController.post(SNSController.java:37)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)

at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)

at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)

at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)

at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)

at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)

at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)

at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)

at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)

at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)

at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1539)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1495)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Unknown Source)

0
0
  • 답변 6

  • 하느아리
    193
    2018-02-22 10:39:23 작성 2018-02-22 10:51:42 수정됨

    SNSController.java:37

    37라인이 저 부분이 맞나요 ????

    0
  • chqhroqkfwk
    72
    2018-02-22 10:45:53

    System.out.println("테스트 : "+timeline.getT_content());

    nservice.test(); //이부분을 주석처리하면 잘 실행됨 주석처리 하지 않으면 nullpoint

    이 부분이 37행은 아닌데 여기를 주석처리하면 실행이 됩니다. 37행은 클래스에서 

    마지막 중괄호가 닫히는 부분입니다. 

    그리고 제가 디버깅을 돌려 봤는데 그때는 f6을 눌러서 한행씩 실행시켰을때는 저 부분이

    에러가 없이 실행되고 넘어갑니다. 도대체 왜 그런지 모르겠습니다ㅜㅜ

    0
  • 하느아리
    193
    2018-02-22 10:56:16

    위 에러 통째로 구글링 하니까 


    http://8boknote.tistory.com/17


    쿼리에 null값이 들어갔을때 나는 문제라네요....

    0
  • chqhroqkfwk
    72
    2018-02-22 11:02:33

    .test()는 db랑은 상관 없는 메서든데 왜 그런지 모르겠네요...

    분명 이 부분에서 에러가 나는데;;

    한번 쿼리쪽을 살펴 볼게요 감사합니다~

    0
  • chqhroqkfwk
    72
    2018-02-22 11:22:44
    프로젝트 클린하니까 해결 됐네요;;; 전에 발생했던 에러가 또 발생했던것 같습니다;;;;
    0
  • 하느아리
    193
    2018-02-22 11:24:22

    ㅎㅎㅎㅎㅎㅎㅎ

    그래도 해결됐으니 축하드려요~~ 

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.