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

    Could not dereference object

    Lasana Crider Newbie

      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