ClassCastException problem...

Ok, here's my problem. The method in question, processFindBookTransaction, is supposed to search go into a binary search tree and find a "book" with a certain key. Here's the code for that method:
  private static Book processFindBookTransaction(Transaction aTransaction)
    Book aBook = (Book) library.findByKey(aTransaction.getISBN());
    if (aBook != null)
      System.out.println(aTransaction.getISBN() +
                         " found: " + aBook );
    else
      System.out.println(aTransaction.getISBN() +
                         " cannot be found");
    return aBook;
  }The problem is in the line reading:
Book aBook = (Book) library.findByKey(aTransaction.getISBN());Here is the code for the method that is accessed in the binary search tree (library being the binary search tree object):
  public Object findByKey(Comparable aKey)
    Node currentNode = rootNode;
    Node parentNode = null;
    boolean found = false;
    while(!found && currentNode != null)
      if(aKey.compareTo(currentNode.getNodeKey()) < 0)
        parentNode = currentNode;
        currentNode = (Node)currentNode.getLeftChild();
      else
        if(aKey.compareTo(currentNode.getNodeKey()) > 0)
          parentNode = currentNode;
          currentNode = (Node) currentNode.getRightChild();
        else
          found = true;
          return currentNode;
    }It throws a ClassCastException, and I can't figure out why. For some reason, it's having a problem explicitly casting an object of type Object to one of type Book. This problem is beyond my comprehension, so I hope someone can help. I appreciate any input. Thank you.

It's happening at runtime, unfortunately. From what I can follow, it start by taking a Transaction object, and just pulling a String from the attributes of it. Then, it takes the String and gives it to the findByKey method, which takes it in as a Comparable. The Comparable is then used in a series of comparisons, narrowing down the potential Nodes for a match. Then, at the end of the find method, it returns a Node, which is then attempted to be cast as a Book. Now, I don't know if it casts it as an Object before returning it, or if it's just giving back the Node to be cast as the Book. (I'm not that fluent in Java to understand the specifics)
By the way, I accidentally cut off the last 2 lines from the find method. The first one read return parentNode; and the second line was just the closing bracket for the whole method.

Similar Messages

  • Applets & ClassCastException problem

    here is the problem...
    I got test.java, an applet, which I can compile without any problem...(I'm using Sun ONE Studio 4)
    but when I try to execute it, it says "Applet not initialized" and the following message appears in the outpout window :
    java.lang.ClassCastException
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:567)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:496)
    at sun.applet.AppletPanel.run(AppletPanel.java:293)
    at java.lang.Thread.run(Thread.java:536)
    the applet doesn't even go in the init() method
    however, if I open test.html, which has the applet on the page, it loads without any problem...
    I'd only like to know what this ClassCastException can be related to...

    Is this as simple as not using the right base class for your applet? I don't know how much experience you have with applets... you may already have this correct, but if not...
    These two lines (or something pretty close, and maybe not adjacent to each other) should appear in the source file of the applet that you are referencing in your web page:
    import java.applet.Applet;
    public class Test extends Applet {Your applet entrypoints are methods you should override in the Applet class.
    -John

  • Java.lang.ClassCastException problem with ApplicationModuleImpl

    Hi, to whom this may be familiar:
    This is from a oracle.adf.controller.struts.actions.DataAction class:
    public class SwitchDAAction extends DataAction
      protected void findForward(DataActionContext actionContext) throws Exception
        super.findForward(actionContext);
        ZBModuleImpl svc = (ZBModuleImpl) actionContext.getBindingContext().findDataControl("ZBModuleDataControl").getDataProvider();
        BillViewImpl oneUser = svc.getBillView1();
    ...ZBModuleImpl is an application module which extends oracle.lbo.server.ApplicationModuleImpl.
    As the last statement indicates, the purpose is to obtain an instance of a view object that is already in the application.
    There is no error at compilation. However, when the application runs, the embedded oc4j gives an error:
    WARNING: Unhandled Exception thrown: class java.lang.ClassCastExceptionand in the browser the first line in the "500 Internal Server Error", shown below, pin-points to the line of code that cast Object to ZBModuleImpl:
    at zb.view.SwitchDAAction.findForward(SwitchDAAction.java:18)I broke up the line into multiple lines to see where exactly the problem is:
    public class SwitchDAAction extends DataAction
      protected void findForward(DataActionContext actionContext) throws Exception
        super.findForward(actionContext);
        BindingContext bdCtx = actionContext.getBindingContext();
        DCDataControl dc = bdCtx.findDataControl("ZBModuleDataControl");
        Object dpd = dc.getDataProvider();
        ZBModuleImpl svc = (ZBModuleImpl) dpd;
        BillViewImpl oneUser = svc.getBillView1();
    ...The error messages always point to that line that does data type casting.
    What is the problem and what can be done to fix it? (I am using JDeveloper 10.1.2.0.0).
    Thanks for your help!
    Newman

    Hi, Valery and Anton:
    Sorry I did not mention the version of Jdev I am using in my last posting. It is 10.1.2. It is so precious someone around still know the older versions.
    Anton, since mine is an older version, I tried to set the custom properties. The name of my application is ZB and the name of the application module is ZBModuleImpl. The name of the view object I am trying to get an instance of is BillViewimpl.
    In the Application Module Editor for ZBModule, at the Custom Properties node, there are names for three properties in the drop-down list: DESCRIPTION, FILE_NAME, DATA_CONTROL_NAME. Not knowing what they are and what they are for, I tried to add two name/value pairs: DESCRIPTION/ZB and DATA_CONTROL_NAME/ZBModuleDataControl. And for the last method on the problem line of code I tried both getDataProvider() and getApplicationModule(), in the following combinations, and none of them work out:
                                                   getDataProvider()     getApplicationModule()
    DESCRIPTION/ZB (only)                                   X                       X
    DATA_CONTROL_NAME/ZBModuleDataControl (only)            X                       X
    (both)                                                  X                       XPlease correct me where I did wrong. I wonder what oracle.jbo.common.ws.WSApplicationModuleImpl is. I even tried
    BillViewImpl oneUser = (ZBModuleImpl) actionContext.getBindingContext().findDataControl("ZBModuleDataControl").getApplicationModule().findApplicationModule("ZBModuleImpl");
    and
    BillViewImpl oneUser = ((ZBModuleImpl) actionContext.getBindingContext().findDataControl("ZBModuleDataControl").getApplicationModule()getApplicationModule()).findViewObject("BillViewImpl");But the problem is always with the typecasting from ApplicationModule to ZBModuleImpl. Is there anything that WSApplicationModuleImpl can do to help out?
    Thanks a lot for your help!
    Newman

  • DSP- ClasscastException Problem in BPM

    I get the Classcastexception in BPM when i try to call an update method from a dsp web service. It is caused by the XML vlidation that happens on the dsp side before the update process (from the dsp server log). I have used the try catch in the logical data service.
    How do I handle the database errors (or XML validation errors) in DSP and send the reason of the error to the client(BPM).
    Edited by: user1587779 on Oct 3, 2008 9:59 AM

    Mike,
    Thanks for the response.
    As I said earlier, I am calling the DSP web services in the BPM to update a table. I am doing this update using the NON-SDO custom update in the DSP layer itself. So the BPM is calling the DSP update method and it is passing 2 parameters, original and current elements. (Not the changed-elements).
    Since I am running the DSP services locally, when I try to do the update from the BPM which is calling the DSP services that are running locally, this is the error I could see from the 'Console' in the Workspace studio.
    Caused by: weblogic.xml.query.exceptions.XQueryDynamicException: {err}XQ0027: Validation failed: error: cvc-complex-type.2.4a: Expected element 'RECV_DT' instead of 'REQ_FL' here in element
    But the error I get in the BPM workspace is as below:
    Caused by: java.lang.ClassCastException: org.apache.axis.message.Text
    at org.apache.axis.message.SOAPFaultBuilder.onEndChild(SOAPFaultBuilder.java:299)
    at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1090)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
    Below is the dsp update method used in BPM:
    declare procedure tns:updateInfo($original as element(csp1:INFO), $current as element(csp1:INFO)) as xs:string? {
         declare $message as xs:string;
         set $message :="failed";
         try{           
              tns:updateInfo_ORIG(gen:generateChangedElement($original,$current,tns:getKeyList()));
         } catch (* into $err , $msg, $obj){
              fn:error(xs:QName("UPDATE_FAILURE"),
    fn:concat("Update failed on due to: ", $err, $msg), $obj);
    set $message := "success";
    return value $message;     
    As you said we will put try/catch in the client side code. But is there any way to tell the client of the exceptions happening in the DSP side?
    Thanks

  • Another ClassCastException problem

    Hi,
    I am getting the following error whenever i try deploy my ear file. The ear file has entity , session and web components and the entity beans implement local interfaces.
    java.lang.ClassCastException: com.sun.enterprise.deployment.EjbExternalDescriptor
    at com.sun.enterprise.deployment.EjbReferenceDescriptor.getValue(EjbReferenceDescriptor.java:198)
    at com.sun.enterprise.deployment.EjbReferenceDescriptor.getJndiName(EjbReferenceDescriptor.java:179)
    at com.sun.enterprise.deployment.xml.RuntimeDescriptorNode.setDescriptor(RuntimeDescriptorNode.java:256)
    at com.sun.enterprise.deployment.xml.RuntimeDescriptorNode.getDocument(RuntimeDescriptorNode.java:1027)
    at com.sun.enterprise.deployment.ApplicationArchivist.writeRuntimeInfo(ApplicationArchivist.java:900)
    at com.sun.ejb.codegen.GeneratorDriver.preDeploy(GeneratorDriver.java:979)
    at com.sun.enterprise.tools.deployment.backend.JarInstallerImpl.deployEjbs(JarInstallerImpl.java:707)
    at com.sun.enterprise.tools.deployment.backend.JarInstallerImpl.deployApplication(JarInstallerImpl.java:221)
    at org.omg.stub.com.sun.enterprise.tools.deployment.backend._JarInstallerImpl_Tie._invoke(Unknown Source)
    at com.sun.corba.ee.internal.corba.ServerDelegate.dispatch(ServerDelegate.java:355)
    Could some one please help me in this regard
    thanks
    vishwak

    Hi,
    I think you have wrong definitions of beans in ejb-jar.xml

  • ClassCastException while inserting in oracle.sql.BLOB

    Hi,
    I have to insert a blob data in to database . I wrote the code . I'm having a ClassCastException problem in the line oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(st.getConnection(), false,
    oracle.sql.BLOB.DURATION_CALL); while trying to store a BLOB value I'm using Oracle 9i. (JDBC classes12.jar).
    if I use the method with a dedicated database connection that specifies the driver as oracle.jdbc.driver.OracleDriver there is no problem .
    But when I use JBoss to run , I will get ClassCastException
    I imagine that somewhere in the code of this method there is a cast of the underlying connection leading to the ClassCastException when used in conjunction with the jboss datasource. The code to save the BLOB is as follows:
    String sql = " update test set code = ? where id = ?  ";
                 BLOB   newBlob = BLOB.createTemporary(dbcon, false, BLOB.DURATION_CALL);
                  newBlob.putBytes(1,data.getBytes());
                  stmt = dbcon.prepareStatement(newsql);
                 stmt.setBlob(1, newBlob);
                 stmt.setInt(2, Studid );
                 stmt.executeUpdate();
                 stmt.close();Can any one tell me how can I get this code to work with the datasource implementation.
    Thanks

    I think this could be a problem with the class loader . Take a look at this thread It should solve your problem.
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=788715

  • ClassCastException in oracle.sql.BLOB.createTemporary

    Hi,
    I'm having a ClassCastException problem using the method oracle.sql.BLOB.createTemporary while trying to store a BLOB value (JDBC classes12.jar). The problem is quite clear - if I use the method with a dedicated database connection that specifies the driver as oracle.jdbc.driver.OracleDriver there is no problem - if I use it with an Orion datasource shipped with Oracle IAS10g it gives me a ClassCastException. I imagine that somewhere in the code of this method there is a cast of the underlying connection leading to the ClassCastException when used in conjunction with the Orion datasource. The code to save the BLOB is as follows:
    oracle.sql.BLOB blob = oracle.sql.BLOB.createTemporary(st.getConnection(), false,
    oracle.sql.BLOB.DURATION_SESSION);
    blob.open(BLOB.MODE_READWRITE);
    OutputStream out = blob.getBinaryOutputStream();
    try {
    out.write((byte[])value);
    out.flush();
    out.close();
    } catch (IOException e) {
    throw new SQLException("failed write to blob" + e.getMessage());
    blob.close();
    ((oracle.jdbc.OraclePreparedStatement)(st)).setBLOB(index, blob);
    My questions are:
    (1) is it possibile to save a BLOB type with a different version of Oracle JDBC without having to rely on the Oracle specific implementation of the JDBC interface (the cast of the PreparedStatement to oracle.jdbc.OraclePreparedStatement is quite ugly and not very portable!).
    (2) if not, then how can I get this code to work with the datasource implementation for Oracle IAS.
    thanks in advance for any help.
    Dara.

    If you are using OCI driver, you may check whether using thin driver would avoid ClassCastException.

  • Problem about blank enumeration option in xsd

    Hello,
    I have xsd schema with an empty enumeration option.
    I use this schema to generate webservice
    When I test the service using the empty enumeration option, it throws
    java.lang.ClassCastException
    [java] at
    abc.PeriodCTCodec.typedInvokeSetter(PeriodCTCodec.java:118)
    [java] at abc.PeriodCTCodec.invokeSetter(PeriodCTCodec.java:74)
    I try to modify the PeriodCTCodec to determine the ClassCastException
    problem.
    I have following result:
    If I use blank enumeration option, the class is java.lang.String
    If I use non-blank enumeration option, the class is abc.PeriodAreaCodeST.
    What's wrong when I use blank enumeration option? Please help!!!!!!!!!!!
    My modified PeriodCTCodec is also attached
    My sample xsd file:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:complexType name="Period.CT">
    <xsd:sequence>
    <xsd:element name="Year" type="v4com:Period.AreaCode.ST"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:simpleType name="Period.AreaCode.ST">
    <xsd:restriction base="xsd:string">
    <xsd:enumeration value=""/>
    <xsd:enumeration value="A"/>
    <xsd:enumeration value="B"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:schema>
    The java exception:
    [java]
    <faultstring>Exception during processing:
    java.lang.ClassCastException (see Fault Detail for
    stacktrace)</faultstring>
    <detail>
    <bea_fault:stacktrace
    xmlns:bea_fault="http://www.bea.com/servers/wls70/webservice/fault/1.0.0">
    java.lang.ClassCastException
    [java] at
    abc.PeriodCTCodec.typedInvokeSetter(PeriodCTCodec.java:118)
    [java] at abc.PeriodCTCodec.invokeSetter(PeriodCTCodec.java:74)
    [java] at
    weblogic.xml.schema.binding.BeanCodecBase.processAllElements(BeanCodecBase.j
    ava:167)
    [java] at
    weblogic.xml.schema.binding.BeanCodecBase.processElements(BeanCodecBase.java
    :146)
    [java] at
    weblogic.xml.schema.binding.BeanCodecBase.deserialize(BeanCodecBase.java:109
    [java] at
    weblogic.xml.schema.binding.RuntimeUtils.invoke_deserializer(RuntimeUtils.ja
    va:428)
    [java] at
    weblogic.xml.schema.binding.RuntimeUtils.invoke_deserializer(RuntimeUtils.ja
    va:328)
    [java] at
    weblogic.webservice.core.DefaultPart.toJava(DefaultPart.java:384)
    [java] at
    weblogic.webservice.core.DefaultMessage.toJava(DefaultMessage.java:484)
    [java] at
    weblogic.webservice.core.handler.InvokeHandler.handleRequest(InvokeHandler.j
    ava:93)
    [java] at
    weblogic.webservice.core.HandlerChainImpl.handleRequest(HandlerChainImpl.jav
    a:143)
    [java] at
    weblogic.webservice.core.DefaultOperation.process(DefaultOperation.java:531)
    [java] at
    weblogic.webservice.server.Dispatcher.process(Dispatcher.java:204)
    [java] at
    weblogic.webservice.server.Dispatcher.doDispatch(Dispatcher.java:176)
    [java] at
    weblogic.webservice.server.Dispatcher.dispatch(Dispatcher.java:96)
    [java] at
    weblogic.webservice.server.WebServiceManager.dispatch(WebServiceManager.java
    :98)
    [java] at
    weblogic.webservice.server.servlet.WebServiceServlet.serverSideInvoke(WebSer
    viceServlet.java:298)
    [java] at
    weblogic.webservice.server.servlet.ServletBase.doPost(ServletBase.java:485)
    [java] at
    weblogic.webservice.server.servlet.WebServiceServlet.doPost(WebServiceServle
    t.java:268)
    [java] at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    [java] at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    [java] at
    weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(Servle
    tStubImpl.java:971)
    [java] at
    weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
    :402)
    [java] at
    weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
    :305)
    [java] at
    weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(W
    ebAppServletContext.java:6350)
    [java] at
    weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubjec
    t.java:317)
    [java] at
    weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
    [java] at
    weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
    ntext.java:3635)
    [java] at
    weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
    :2585)
    [java] at
    weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
    [java] at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
    [java]
    </bea_fault:stacktrace></detail></env:Fault></env:Body></env:Envelope>______
    [PeriodCTCodec.java]

    Hi,
    Can anyone please tell me the solution for this ?
    Actually I have used EDIT_MASK to rectify filter problem by passing conversion exit.
    But for those fields which are not having any conversion exit, the filter problem still exists.
    Please help on this. Thanks in advance.

  • ClassCastException While Narrowing

    Hi,
    I have my application deployed as EAR file, with a WAR and two JAR for the statelesss session beans. On Server start up I call a servlet (in the WAR), which invokes the EJB deployed in one of the JAR file. At that instance it is giving the following Error:
    Exception :Cannot narrow remote object to au.com.three.hutchison.hss.ejb.staticinfo.StaticInfoHome
    java.lang.ClassCastException: Cannot narrow remote object to au.com.three.hutchison.hss.ejb.staticinfo.StaticInfoHome
         at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:242)
         at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
         at au.com.three.hutchison.hss.service.HSSServiceFactory.narrow(Unknown Source)
         at au.com.three.hutchison.hss.service.HSSServiceFactory.lookupHome(Unknown Source)
         at au.com.three.hutchison.hss.service.HSSServiceFactory.getRemote(Unknown Source)
         at au.com.three.hutchison.init.InitConfigInfoServlet.init(Unknown Source)
         at weblogic.servlet.internal.ServletStubImpl$ServletInitAction.run(ServletStubImpl.java:1070)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
         at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:893)
         at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:842)
         at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:782)
         at weblogic.servlet.internal.WebAppServletContext.preloadServlet(WebAppServletContext.java:3236)
    The same code used to work fine before, but I had some class loader issues to resolve which i set the 'prefer-web-inf-classes' to true in the weblogic.xml of the WAR. However after that I started getting the ClassCastException problem..
    Any Help Would be Hghly Appreciated
    Thanks
    Nitin

    here's the weblogic-application.xml that i have used to specify different classloaders
    <!DOCTYPE weblogic-application PUBLIC '-//BEA Systems, Inc.//DTD WebLogic Application 8.1.0//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-application_2_0.dtd'>
    <weblogic-application>
         <classloader-structure>
              <module-ref>
                   <module-uri>hssWebApp.war</module-uri>
              </module-ref>
              <module-ref>
                   <module-uri>StaticInfoBean/StaticInfoBean.jar</module-uri>
              </module-ref>
              <module-ref>
                   <module-uri>HSSGWSBean/HSSGWSBean.jar</module-uri>
              </module-ref>
         </classloader-structure>
    </weblogic-application>

  • WARs and ClassCastException redux...

    so i've been poring through messages in this newsgroup.. and i've
              noticed that many people have run into the ClassCastException problem
              with WARs that have servlets forwarding on to jsps using objects
              stuffed away in sessions..
              i've been trying to get my web application working as a WAR, but i've
              run into this very problem. (jsps try to retrieve object from session
              that was stored away by controlling servlet, but get a
              ClassCastException) is it true that, because weblogic uses different
              classloaders for servlets and jsps in a WAR, WARs are essentially
              worthless for my app? is there a solution to this? is bea addressing
              this too?
              thx
              leo
              

    i read your solution on previous posts, and it works.. but is this the
              only solution? it seems odd that the classloading behavior would
              differ depending on whether you executed a JSP or servlet first. do
              you mean that i have to invoke JSPs controlled by all my servlets
              first? or just one of them, and the rest will behave accordingly?
              thx
              leo
              On Thu, 21 Dec 2000, Cameron Purdy wrote:
              > After starting the server, invoke a JSP before invoking the first servlet.
              >
              > Peace,
              >
              > --
              > Cameron Purdy
              > Tangosol, Inc.
              > http://www.tangosol.com
              > +1.617.623.5782
              > WebLogic Consulting Available
              >
              >
              > "Leo Kim" <[email protected]> wrote in message
              > news:Pine.OSX.4.30.0012191647220.1267-100000@ginormous...
              > > so i've been poring through messages in this newsgroup.. and i've
              > > noticed that many people have run into the ClassCastException problem
              > > with WARs that have servlets forwarding on to jsps using objects
              > > stuffed away in sessions..
              > >
              > > i've been trying to get my web application working as a WAR, but i've
              > > run into this very problem. (jsps try to retrieve object from session
              > > that was stored away by controlling servlet, but get a
              > > ClassCastException) is it true that, because weblogic uses different
              > > classloaders for servlets and jsps in a WAR, WARs are essentially
              > > worthless for my app? is there a solution to this? is bea addressing
              > > this too?
              > >
              > > thx
              > > leo
              > >
              >
              >
              >
              

  • ClassCastException on Serializable Object

    Hello,
    I access an Ejb method that return a List of DictionaryClassDTO.
    I've got a ClassCast Exception on line * on the code below
    List varListFromServer = this.loadFromServer(varListOfDictionaryClassNameForServer);
    for(Iterator i = varListFromServer.iterator(); i.hasNext(); ) {
       Object varObject = i.next();
       DictionaryClassDTO varServerDictionaryClass = (DictionaryClassDTO)varObject; // *
    }NB. DictionaryClassDTO implements Serializable interface.
    I think the exception is link to ClassLoader :
    varObject classloader is instance of sun.rmi.server.LoaderHandler$Loader
    varServerDictionaryClass classloader is instance of org.eclipse.core.runtime.adaptor.EclipseClassLoader
    Can someone have an idea how perform the cast ?
    thanks

    Hi,
    Did you find a solution/workaround for your ClassCastException problem? I'm running into a similar problem.
    In my case, the object from the EJB method call is loaded by sun.misc.Launcher$ExtClassLoader, while I'm casting it to a variable loaded with org.eclipse.core.runtime.adaptor.EclipseClassLoader (parent: org.eclipse.osgi.framework.adaptor.core.AbstractFrameworkAdaptor$ParentClassLoader). I'm still trying to sort out the classloaders used by an Eclipse plugin.
    Thanks, Steve

  • Weblogic6.0 classloader

    I can't seem to find any documentation on the mentioned
    improvements of the classpath and classloader on weblogic6.0.
    Could someone please explain these improvements or help to
    provide me with an appropriate link?
    Has the dreaded ClassCastException problems been eliminated?
    Thanks

    http://e-docs.bea.com/wls/docs60/programming/topics.html#1037589
    Igor Zavialov, [email protected]
    Consulting Services available
    "Jas" <[email protected]> wrote in message
    news:[email protected]..
    >
    >
    I can't seem to find any documentation on the mentioned
    improvements of the classpath and classloader on weblogic6.0.
    Could someone please explain these improvements or help to
    provide me with an appropriate link?
    Has the dreaded ClassCastException problems been eliminated?
    Thanks

  • Problem with ClassCastException in web application

    Hello,
              I'm trying to deploy a web application in WLS 5.1 and I'm getting the
              "dreaded" ClassCastException every time when JSP tries to read a bean
              from the request or session. Under my architecture (actually it's just
              the regular "model 2" ) bean is populated by a servlet, set on the
              request and then retrieved by JSP (servlet forwards to JSP). Everything
              work fine when I register servlets in weblogic.properties, but
              ClassCastException is thrown on any attempt to read from the request if
              the same JSPs and servlets are deployed as web application.
              Has anybody come across the same problem?
              Thanks in advance for help.
              Alexander
              

    Hello,
              This is all well and good as a temporary bug, but it's totally unrealistic for
              the future. Two points:
              * The ClassLoader doesn't need to be discarded, it just needs to be cleared.
              * Other servlet engines seem to be able to handle this.
              Hope it's on its way to resolution!
              TDoan wrote:
              > Alexander:
              >
              > I had some problem with ClassCastException, and recently I found out what it
              > was that causing it. I'm sure if this is the same problem you are having,
              > but please read the following paragraph.
              >
              > I cutted this from http://www.weblogic.com/docs51/classdocs/API_servlet.html
              > ClassCastException and HTTP Sessions
              >
              > You might encounter a ClassCastException while developing servlets that use
              > HTTP sessions. This could happen as a result of the following set of events:
              >
              > a.. You store a reference to a custom class, myFoo, in an HTTP session.
              >
              > b.. While in mid-session, you change your servlet (or JSP or JHTML),
              > causing it to be reloaded. In fact, it is necessary for it to be reloaded by
              > a completely new class loader, and the old class loader that had previously
              > loaded it must be discarded.
              >
              > c.. Because your custom class myFoo is also located under the servlet
              > classpath, it too is reloaded by the new class loader.
              >
              > d.. Now, when you retrieve myFoo from the HTTP session, you cast it to the
              > expected type, but you recieve a ClassCastException. The exception is thrown
              > even if class myFoo has not changed. Because it has been loaded by a
              > different class loader, it is regarded by the JVM as incompatible.
              > Note: If you are using session persistence, the class contents must be
              > serialized, and you will not encounter this exception.
              >
              > Here are some suggested work-arounds to this problem:
              >
              > a.. Do not place your class myFoo in the servlet classpath. Instead, place
              > it in the system classpath or the weblogic.class.path, which are accessible
              > by WebLogic Server. The class will not be reloaded when the servlet is
              > modified. This drawback to this solution is that you cannot prototype the
              > myFoo class, because you must restart the server in order to reload the
              > class after it is modified.
              >
              > b.. If you need to prototype the class, you can write a wrapper method
              > within it to store and retrieve its contents to and from the session. You do
              > not access the class directly from the session, but instead call it is
              > wrapper methods to store or populate it is contents from the session. As
              > long as you use standard Java class types to store the class contents, they
              > will not be reloaded when the servlet is reloaded. This approach has
              > performance drawbacks because your wrapper methods would need to set or get
              > multiple name=value pairs for each class's attributes.
              >
              > c.. Another work-around is to catch the ClassCastException, and replace
              > the old class that is stored in the session with a newly instantiated class,
              > or remove it from the session. Unfortunately, you lose the session data that
              > was previously stored in the class, so you must write your application to
              > handle this scenario. This is the easiest solution to the problem-remember
              > that you should not be storing critical information in an HTTP session, but
              > rather storing it in a database.
              > Note: The ClassCastException generally occurs while you are developing
              > your servlets, and should not be an issue in a stable production system. If
              > you are upgrading your system online, you might wish to warn your customer
              > base.
              >
              > Hope it helps,
              > Tin
              >
              > "Alexander Ananiev" <[email protected]> wrote in message
              > news:[email protected]...
              > > Hello,
              > >
              > > I'm trying to deploy a web application in WLS 5.1 and I'm getting the
              > > "dreaded" ClassCastException every time when JSP tries to read a bean
              > > from the request or session. Under my architecture (actually it's just
              > > the regular "model 2" ) bean is populated by a servlet, set on the
              > > request and then retrieved by JSP (servlet forwards to JSP). Everything
              > > work fine when I register servlets in weblogic.properties, but
              > > ClassCastException is thrown on any attempt to read from the request if
              > > the same JSPs and servlets are deployed as web application.
              > > Has anybody come across the same problem?
              > >
              > > Thanks in advance for help.
              > > Alexander
              > >
              

  • ClassCastException error problem

    Hi all,
    I am relatively new to java and confused with the following problem. The below code compilers but returns a ClassCastException error when run.
    private List<TableOne> query = new ArrayList<TableOne>();
           private TableTwo tableTwo;
    //create an array of values
            for (Double value : array) {
              query = ..result from sql query (needs to be list using hibernate)
             for (TableOne queryValue :  query ) {
             //something
    public List<TableOne> getTableOne() {
            return query;
        public List getQuery()
            return this.Query;
               The ClassCastException error occurs on the second for loop? Is this because the wo objects are not of the same type? Any suggetions would be great, thanks in advance

    Hi,
    look, List<TableOne> should mean that You have a list of TableOne objects. It seems like logic mistake. In addition, You are already have instance of query why do You need to assign it once more?
    Now about ex. You sayed it is in the second loop and put almost nothing there. It seems like You have a mistake in //something ;)

  • Sun One EJB problem - PortableRemoteObject.narrow ClassCastException...

    Hi all,
    I'm using Sun One app server 7 for the first time and am having a bit of difficulty. I have deployed a very simple EAR containing one stateless session bean just to test it. The ear appears to have deployed correctly but PortableRemoteObject.narrow is throwing a ClassCastException when trying to do a remote lookup on the bean.
    I'm using the following env settings...
    initialContextFactory = com.sun.enterprise.naming.SerialInitContextFactory
    providerUrl = iiop://127.0.0.1:3700The lookup appears to work okay - this line of code executes successfully
    Object objref = initialContext.lookup(jndiHomeName);...objref appears to initalise succesfully (if I toString() it I get an iiop stream of some sort). However, it is the next line that is failing...
    Object obj = PortableRemoteObject.narrow(objref, homeClass);...this is the exception I get...
    java.lang.ClassCastException
         at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unknown Source)
         at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
         at com.scorlog.ServiceLocator.getRemoteHome(ServiceLocator.java:145)Furthermore, when PortableRemoteObject.narrow() executes, I get the following console exception on the server...
    com.sun.corba.ee.internal.core.DuplicateServiceContext
            at com.sun.corba.ee.internal.core.ServiceContexts.put(ServiceContexts.java:208)
            at com.sun.corba.ee.internal.iiop.ServerRequestImpl.getServiceContextsForReply(ServerRequestImpl.java:258)
            at com.sun.corba.ee.internal.iiop.ServerRequestImpl.createResponse(ServerRequestImpl.java:89)
            at com.sun.corba.ee.internal.POA.SubcontractResponseHandler.createReply(SubcontractResponseHandler.java:50)
            at org.omg.CosNaming.NamingContextExtPOA._invoke(NamingContextExtPOA.java:377)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:569)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:211)
            at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:113)
            at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:275)
            at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:83)
            at com.iplanet.ias.corba.ee.internal.iiop.ServicableWrapper.service(ServicableWrapper.java:25)
            at com.iplanet.ias.util.threadpool.FastThreadPool$ThreadPoolThread.run(FastThreadPool.java:288)
            at java.lang.Thread.run(Thread.java:534)
    FINE: No SAS context element found in service context listI have seen the forum that other users have had similar problems and the suggestion was that the client can't see the ejb stubs. I don't think this is the problem in my case as I deployed the same ear on weblogic 7 (obviously substituting sun-ejb-jar.xml for a weblogic-ejb-jar.xml) and successfully executed the same client code for the remote lookup.
    My feeling is that the problem revolves around the JNDI binding. Could it be the case that even though the object is binding properly, the app server doesn't realise it is an ejb and not a jdbc/jms/mail object? The documentation gives details on looking up a JDBC, javamail, URL, JMS resource (http://docs.sun.com/source/817-2177/djjndi.html) but not ejb so I could be doing something simple wrong here...
    My sun-ejb-jar.xml is as follows....
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Generated by XDoclet -->
    <sun-ejb-jar>
        <enterprise-beans>
            <ejb>
                <ejb-name>SBTest</ejb-name>
                <jndi-name>ejb/SBTestBean</jndi-name>
            </ejb>
        </enterprise-beans>
    </sun-ejb-jar>However, I noticed on another thread, a user had some additional elements under their <ejb> tag like this...
    <?xml version="1.0" encoding="UTF-8"?>
    <sun-ejb-jar>
      <enterprise-beans>
        <name>Ejb1</name>
        <ejb>
          <ejb-name>HelloBean</ejb-name>
          <jndi-name>HelloBean</jndi-name>
          <ejb-ref>
            <ejb-ref-name>ejb/helloBean</ejb-ref-name>
            <jndi-name>HelloBean</jndi-name>
          </ejb-ref>
        </ejb>
      </enterprise-beans>
    </sun-ejb-jar>However, when I tried to add and <ejb-ref> element to my xml doc the ear failed to deploy. This is the error I get in the admin console...
    Error
    Deployment Error -- Error while running ejbc -- Fatal Error from EJB Compiler -- --
    Failed to load deployment descriptor for: testApp cause: Error converting J2EE-
    specific ejb xml to object representation: testApp.jar app_testApp Generated by
    XDoclet This bean has no ejb reference by the name of [ejb/SBtest]
    ejb/SBTestSBTestThis problem is eating up my time and being made all the more frustrating by the fact that a) it deploys on weblogic and b) the documentation is terrible. Even the sample application that comes with sun one only provides the .class files for the code that does the ejb look up and not the .java so you can't see how they hell they do it!
    Unfortunately I am tied to using Sun One so I really need to solve this problem fast. If anyone can provide any help I'd greatly appreciate it.
    Cheers,
    John :)

    I am having the same problem after upgrading to Sun One from iplanet. Any clue?

Maybe you are looking for