1 Reply Latest reply on Feb 23, 2004 8:02 AM by spohl

    JMS  ClassCastException on the lookup

    pbandino

      I am trying to create a simple applet that receives queue messages. I get a ClassCastException on the lookup.
      I am using Netscape browser. My code is the following.

      Hashtable environment = new Hashtable();
      environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
      environment.put(Context.PROVIDER_URL, "nova_test_win:1099");
      environment.put("java.naming.rmi.security.manager", "no");
      environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming");
      Context context = new InitialContext(environment);
      QueueConnectionFactory queueFactory = null;
      try{
      Object obj = context.lookup(factoryJNDI);
      System.out.println(obj.toString());

      queueFactory = (QueueConnectionFactory)obj;

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

      >>>>>>>>
      System.out.println and ex.printStackTrace() printed the following message

      Reference Class Name: org.jboss.mq.SpyConnectionFactory
      Type: DCF
      Content: [B@60478

      java.lang.ClassCastException: javax.naming.Reference

      at com.caliari.nova.applet.test.HelloPublisher.<init>(HelloPublisher.java:81)

      at com.caliari.nova.applet.NSApplet.jbInit(NSApplet.java:90)

      at com.caliari.nova.applet.NSApplet.init(NSApplet.java:61)

      at sun.applet.AppletPanel.run(Unknown Source)

      at java.lang.Thread.run(Unknown Source)

      Publishing message: Hello World no. 1

      java.lang.NullPointerException

      at com.caliari.nova.applet.test.HelloPublisher.publish(HelloPublisher.java:110)

      at com.caliari.nova.applet.NSApplet.jbInit(NSApplet.java:101)

      at com.caliari.nova.applet.NSApplet.init(NSApplet.java:61)

      at sun.applet.AppletPanel.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
      >>>>>>>

      Can anybody help.
      Thanx,
      Paolo

        • 1. Re: JMS  ClassCastException on the lookup
          spohl

          The following solved my problems with java plugin technology (applets), ClassCastException and CLASSPATH:

          http://forum.java.sun.com/thread.jsp?thread=432365&forum=40&message=1934477

          for convenience & full-text-search purposes:

          "I had a similar problem when I was trying to use JNDI from java code invoked by the bridge. Running the same java code from the command line worked fine, invoking it through the bridge spat out a ClassNotFound.

          I tracked the problem to the classloading mechanism used by JNDI, which relies on the context class loader (see the javadoc for java.lang.Thread). The bridge does not set the context class loader (leaving it null), which results in JNDI trying to load the InitialContextFactory implementation from the bootstrap classloader. The bootstrap classloader only loads the most essential libraries (rt.jar primarily), and does not see your extended classpath.

          My solution was to insert a setContextClassloader call in my Java code, setting the context classloader to the classloader of my own class. That solved the problem in my case.

          Hope this can help you,

          Maarten"