3 Replies Latest reply on Dec 14, 2007 11:00 AM by lasanac

    Could not dereference object

    lasanac

      Hello,

      I keep this error:


      javax.naming.NamingException: Could not dereference object [Root exception is java.lang.NullPointerException]
      at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1152)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:707)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:589)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at com.kt.dao.DBConnection.doConnection(DBConnection.java:46)
      at com.kt.dao.MakeConnectionTest.main(MakeConnectionTest.java:17)
      Caused by: java.lang.NullPointerException
      at org.jnp.interfaces.NamingContextFactory.getObjectInstance(NamingContextFactory.java:83)
      at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
      at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1127)
      at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1144)
      ... 5 more



      I am running on JBoss 4.2.0GA
      using JDK 1.5
      DB is MySQL5.0
      here is my code:

      public Hashtable doEnvironment(){

      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      return env;
      }

      public String doConnection(Hashtable env){

      try{


      Reference ref = new Reference("javax.sql.DataSource", "org.jnp.interfaces.NamingContextFactory", null);
      System.out.println("step 1");
      Context ctx= new InitialContext(env);
      ctx.rebind("java:MySQLDS", ref);
      //ctx = new InitialContext();
      System.out.println("step 2");
      DataSource ds = (DataSource)ctx.lookup("java:MySQLDS");

      System.out.println("step 3 " + obj.getClass().getName().toString());


      }
      catch(Exception ex){
      ex.printStackTrace();
      }


      return null;


      It nevers gets to step 3...

      Is there something wrong with what I am doing? Please help


      LC

        • 1. Re: Could not dereference object
          jaikiran

          What is client application trying to do? Especially, what's the purpose of using

          ctx.rebind("java:MySQLDS", ref);


          • 2. Re: Could not dereference object
            lasanac

            I am just testing the back end of the application. Currently I used:

            ctx.rebind("java:MySQLDS", ref);

            as it got rid of another problem that I had earlier. That was a CastException for Reference object. I did retest it without that line and got the same error.

            New Code:

            System.out.println("step 1");
            Context ctx= new InitialContext(env);
            System.out.println("step 2");
            DataSource ds = (DataSource)ctx.lookup("java:MySQLDS");
            System.out.println("step 3 ");

            • 3. Re: Could not dereference object
              lasanac

              Please disregard my last post!!!!!!


              When I don't use:

              ctx.rebind("java:MySQLDS", ref);


              I get the following error:

              step 1
              step 2
              java.lang.ClassCastException: javax.naming.Reference
              at com.kt.dao.DBConnection.doConnection(DBConnection.java:43)
              at com.kt.dao.MakeConnectionTest.main(MakeConnectionTest.java:17)