Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Fix Null Pointer Exception When calling Implementation Via Interface from Another Module

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 538
    Answer it

    When I try to call an implementation from another module via interface, I get null pointer exception

     

    • I need help! I get nullpointer exception, after deployment.
    • I have an interface AirlineClient in 'com.airline.model.hook' module.
    • The implementation class is AirlineClientImpl in 'com.airline.client'
    • I want to inject AirlineClient from the class Airline on 'com.airline.web' module.

     

    Both com.airline.client and com.airline.web has dependency to com.airline.model. But they have no dependency to each other.

     

    AirlineClient and AirlineClientImp are normal java classes (no EJB,CDI..) and Airline is a WebServlet.

     

    But when I deploy the project on glassfish I always get NullPointer exception :(

     

            public class AirlineClientImpl implements AirlineClient {
        	
            private ResteasyWebTarget webTarget;
            private ResteasyClient client;
        
        
            public AirlineClientImpl() {
                client = new ResteasyClientBuilder().build();
            }
        
            public AirlineInformation getAirline(City city) throws IOException {
                ....
            }
        }

     

      public interface AirlineClient {
       public AirlineInformation getAirline(City city) throws IOException;
      }
    @WebServlet("/Airline")
      public class Airline extends HttpServlet {
       private static final long serialVersionUID = 1L;
       
       @Inject
       AirlineClient client;
        
        public Airline() {
          super();
        }
     
       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ....
         AirlineInformation airline = client.getAirline(city);
         ....
       }
     
       protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       }
     
      }


        
        
       When i deploy the project and call a website which calls Airline servlet I get null pointer exception here:  client.getAirline().
       

    Thank you a a lot for all the help.
     

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: