0 Replies Latest reply on Jul 24, 2013 12:29 AM by logandtr

    NullPointerException when try to get data

    logandtr Newbie

      Hi all!

       

      I've any problem with my test app.

       

      When in a get() method I try to get data from my DB MySQL, I receve this:

       

       

      HTTP Status 500 -


      type Exception report

      message

      description The server encountered an internal error () that prevented it from fulfilling this request.

      exception

      org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:340) org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214) org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190) org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:540) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 

      root cause

      java.lang.NullPointerException com.zen.ws.UtentiResource.getUtente(UtentiResource.java:28) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) java.lang.reflect.Method.invoke(Unknown Source) org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155) org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257) org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222) org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211) org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 

      This is my code:

       

      @Stateless
      @LocalBean
      public class UtentiHome {
      
          private static final Log log = LogFactory.getLog(UtentiHome.class);
      
          @PersistenceContext
          private EntityManager entityManager;
      
      
      public Utenti findById(int id) {
      
      
      
      
      
      
      Utenti instance = entityManager.find(Utenti.class, id);
      
      
      
      
      
      
      return instance;
      
      
      }
      
      }
      

       

       

      @Path("/UtentiREST")
      @Stateless
      @LocalBean
      public class UtentiResource {
      
          @EJB
          private UtentiHome uh;
      
          @GET()
          @Path("/{id}")
          public Utenti getUtente(@PathParam("id") int id) {
              return uh.findById(id);
          }
      }
      

       

      Someone can help me please? =)