7 Replies - 5147 Views - Last Post: 06 July 2012 - 08:28 AM

#1 Zdrenka  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 116
  • Joined: 24-November 09

Vector cannot be cast ArrayList..

Posted 25 June 2012 - 03:22 AM

Does anyone know why I'm getting the following error:

Caused by: java.lang.ClassCastException: java.util.Vector cannot be cast to java.util.ArrayList

on this line:
Query query = manager.createNativeQuery(sql);


in this method:

  public DateUpdateEventList getDateUpdateEvents() {
        DateUpdateEventList dispList = new DateUpdateEventList();
        String sql = "select * from display where date_update_frequency > 0";
        Query query = manager.createNativeQuery(sql);
        List<Vector> results = query.getResultList();
        for (Vector v : results) {
            dispList.addDate(v);
        }
        return dispList;
    }



I've been working on this for days and it doesn't seem to make any sense as I'm not using an ArrayList. I'm starting to think there's something wrong with NetBeans :(

Is This A Good Question/Topic? 0
  • +

Replies To: Vector cannot be cast ArrayList..

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: Vector cannot be cast ArrayList..

Posted 25 June 2012 - 03:30 AM

Please post complete stack trace
http://technojeeves....free/118-errors

Quote

on this line:


Most unlikely.

Quote

List<Vector> results = query.getResultList();

should probably be
List results = query.getResultList();

This post has been edited by g00se: 25 June 2012 - 03:32 AM

Was This Post Helpful? 0
  • +
  • -

#3 Zdrenka  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 116
  • Joined: 24-November 09

Re: Vector cannot be cast ArrayList..

Posted 25 June 2012 - 03:32 AM

javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
        java.rmi.RemoteException: null; nested exception is: 
        java.lang.ClassCastException: java.util.Vector cannot be cast to java.util.ArrayList
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
        java.rmi.RemoteException: null; nested exception is: 
        java.lang.ClassCastException: java.util.Vector cannot be cast to java.util.ArrayList
        at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:243)
        at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:205)
        at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:152)
        at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(BCELStubBase.java:225)
        at com.jmwrti.session.event.__EventRemote_Remote_DynamicStub.getDateUpdateEvents(com/jmwrti/session/event/__EventRemote_Remote_DynamicStub.java)
        at com.jmwrti.session.event._EventRemote_Wrapper.getDateUpdateEvents(com/jmwrti/session/event/_EventRemote_Wrapper.java)
        at com.jmwrti.rtiserver.EventProcessor.getDateUpdates(EventProcessor.java:212)
        at com.jmwrti.rtiserver.EventProcessor.run(EventProcessor.java:302)
        at java.lang.Thread.run(Thread.java:722)
Caused by: java.rmi.RemoteException: null; nested exception is: 
        java.lang.ClassCastException: java.util.Vector cannot be cast to java.util.ArrayList
        at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.java:251)
        at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1411)
        at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
        at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:210)
        at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:117)
        at $Proxy86.getDateUpdateEvents(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor628.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:154)
        at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:687)
        at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:227)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
        at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
        at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
        at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Caused by: java.lang.ClassCastException: java.util.Vector cannot be cast to java.util.ArrayList
        at com.jmwrti.session.event.EventBean.getDateUpdateEvents(EventBean.java:444)
        at sun.reflect.GeneratedMethodAccessor629.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
        at com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2920)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4011)
        at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
        ... 16 more
javax.ejb.EJBException: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
        java.rmi.RemoteException: null; nested exception is: 
        java.lang.ClassCastException: java.util.Vector cannot be cast to java.util.ArrayList
        at com.jmwrti.session.event._EventRemote_Wrapper.getDateUpdateEvents(com/jmwrti/session/event/_EventRemote_Wrapper.java)
        at com.jmwrti.rtiserver.EventProcessor.getDateUpdates(EventProcessor.java:212)
        at com.jmwrti.rtiserver.EventProcessor.run(EventProcessor.java:302)
        at java.lang.Thread.run(Thread.java:722)


Sorry if this looks a mess I wasn't to sure how I should paste this in..

This post has been edited by Zdrenka: 25 June 2012 - 03:33 AM

Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: Vector cannot be cast ArrayList..

Posted 25 June 2012 - 03:39 AM

Quote

Sorry if this looks a mess I wasn't to sure how I should paste this in..


That's fine. Did you make the change i mentioned?
You could follow that line with the following and tell me what it prints

System.out.println(results.get(0).getClass());

Was This Post Helpful? 0
  • +
  • -

#5 Zdrenka  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 116
  • Joined: 24-November 09

Re: Vector cannot be cast ArrayList..

Posted 25 June 2012 - 03:44 AM

Yeah I tried what you mentioned

    public DateUpdateEventList getDateUpdateEvents() {
        DateUpdateEventList dispList = new DateUpdateEventList();
        String sql = "select * from display where date_update_frequency > 0";
        Query query = manager.createNativeQuery(sql);
        List results = query.getResultList();
        System.out.println(results.get(0).getClass());
        //for (Vector v : results) {
            //dispList.addDate(v);
        //}
        return dispList;
    }



However I got the same error and a HUGE list of the following:
ERROR: null
ERROR: null
ERROR: null
ERROR: null

Maybe something wrong with my manager.createNativeQuery(0)?

I have just realised that that return statement would return a null :\ *face palm*

This post has been edited by Zdrenka: 25 June 2012 - 03:45 AM

Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,197
  • Joined: 20-September 08

Re: Vector cannot be cast ArrayList..

Posted 25 June 2012 - 04:03 AM

I haven't used this api before so it's new territory for me. Can you make sure you've posted exactly the output you get from the exact code you last posted please?
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10396
  • View blog
  • Posts: 38,463
  • Joined: 27-December 08

Re: Vector cannot be cast ArrayList..

Posted 25 June 2012 - 07:50 AM

*Moved to Java EE*
Was This Post Helpful? 0
  • +
  • -

#8 RCR  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 33
  • Joined: 04-July 12

Re: Vector cannot be cast ArrayList..

Posted 06 July 2012 - 08:28 AM

G00se had the right syntax, your problem is you have to declare a vector or a list in any situation as a vector or a list. You can only cast it once it has a value, and this is why you're getting a null pointer error. You can only cast it once it has a value.

That's pretty much the keyword
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1