0 Replies Latest reply on Aug 8, 2012 2:30 PM by John Scott

    Problem with my first EJB application

    John Scott Newbie

      Dear friends , i have a problem with my first EJB application.

       

      I hava create this bussiness interface

       

       

      package ejb;
      
      import javax.ejb.Local;
      import javax.ejb.Remote;
      
      @Local
      public interface CountryCapital {
          public String capitalName(String countryName);
      }
      

       

       

      I have create a SessionBean

       

       

      package ejb;
      
      import javax.ejb.EJB;
      import javax.ejb.Stateless;
      
      @Stateless
      public class CountryCapitalBean implements CountryCapital,CountryCapitalLocal{
          
          
          public String capitalName(String countryName)
          {
              String capital=new String("No such country");
              if (countryName.equalsIgnoreCase("India"))
              {
                  capital="New Delhi";
              }
              if (countryName.equalsIgnoreCase("United States Of America"))
              {
                  capital="Washington DC";
              }
              if (countryName.equalsIgnoreCase("China"))
              {
                  capital="Beijing";
              }
      
          
              return capital;
      
          }
      }
      

       

       

      Finally, I implemented a client and wanted to inject the bean but it does not work

       


      package appclient;
      
      
      import javax.ejb.EJB;
      
      
      public class ApplicationClient {
          
          @EJB
          private static CountryCapital countryCapital;
          
          public static void main(String [] args){
               
              countryCapital.capitalName("India");
               }  
      }  
      

       

      This is the error , the injection does not work

      Exception in thread "main" java.lang.NullPointerException
          at appclient.ApplicationClient.main(ApplicationClient.java:25)