5 Replies Latest reply on Sep 30, 2002 11:42 AM by sgturner

    ClassCastException

    gimi

      Hi,

      I am trying to get a HomeObject as follows:
      [pre]
      objRef = (SvcJ2XHome) initial.lookup("SvcJ2X");
      svcJ2XHome = (SvcJ2XHome)PortableRemoteObject.narrow(objRef, SvcJ2XHome.class);
      [/pre]

      but there is a problem casting respectively narrowing the object.. the first statement works and returns an object, but by narrowing I get the following error

      [pre]
      java.lang.ClassCastException
      at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
      at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
      at bbt.test.client.GetAllNodesTests.setUp(GetAllNodesTests.java:128)
      at junit.framework.TestCase.runBare(TestCase.java:138)
      at junit.framework.TestResult$1.protect(TestResult.java:106)
      at junit.framework.TestResult.runProtected(TestResult.java:124)
      at junit.framework.TestResult.run(TestResult.java:109)
      [/pre]

      Is this a JBoss-problem or am I doing something wrong??

      Thanx in advance,
      gimi

        • 1. Re: ClassCastException
          jasonbrome

          You shouldn't be casting the return value of initial.lookup("SvcJ2X")

          Try this:

          (Assuming that objRef of type Object, and svcJ2XHome of type SvcJ2XHome, have been previously declared)

          objRef = initial.lookup("SvcJ2X");
          svcJ2XHome = (SvcJ2XHome)PortableRemoteObject.narrow(objRef, SvcJ2XHome.class);

          • 2. Re: ClassCastException
            jasonbrome

            Ok, scrub that - I've just re-read your message, and see that the ClassCastException occurs on the PortableRemoteObject.narrow. Any chances that what is bound to SvcJ2X is not what you're expecting?

            • 3. Re: ClassCastException
              e_zhao

              Anybody can help this?(I am using Jboss3.0.2)

              Object objref = ctx.lookup("Register");
              RegisterHome home = (RegisterHome) javax.rmi.PortableRemoteObject.narrow(objref, RegisterHome.class);

              java.lang.ClassCastException
              at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
              at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
              at com.highbase.servlet.RegisterServlet.doGet(Unknown Source)
              at com.highbase.servlet.RegisterServlet.doPost(Unk

              • 4. Re: ClassCastException
                e_zhao

                ClassCastException:

                The problem happends when I update my servlet without modifying EJB files, and re-deploy my ear file.

                If I re-start JBOSS server, everything works fine now.

                • 5. Re: ClassCastException
                  sgturner

                  Don't need narrowing in JBoss. Not sure this will fix problem, but try:

                  SvcJ2XHome home = (SvcJ2XHome)initial.lookup ("SvcJ2X");