3 Replies Latest reply on Mar 9, 2004 5:12 AM by rais

    Getting ClassCastException in client

    aslani Newbie

      Am getting an ClassCastException when I try to parse Object to File and I really dont know why? This is the find method in BMP bean:

      public Enumeration ejbFindAll()
       {
       Vector l = new Vector();
       Connection con = null;
       ResultSet rs = null;
       try
       {
       con = getConnection();
       Statement s = con.createStatement();
       rs = s.executeQuery("SELECT * FROM file");
       while (rs.next())
       {
       File f = new File(rs.getInt("id"),
       rs.getString("title"),
       rs.getInt("length"),
       rs.getDate("startDate"),
       rs.getDate("endDate"),
       rs.getString("description"),
       rs.getDate("created"),
       rs.getString("userName"),
       rs.getInt("typeId"));
      
       l.add(f);
       }
       }
       catch (SQLException e)
       {
       e.printStackTrace();
       }
       finally
       {
       try
       {
       if (rs != null)
       {
       rs.close();
       }
       if (con != null)
       {
       con.close();
       }
       }
       catch (SQLException e)
       {
       }
       }
       return l.elements();
       }



      This is the method where I want to retrieve the data from Enumeration:



      public void getDataBMP()
       {
       setRowCount(0);
       Iterator it=null;
       Enumeration col=null;
      
       try
       {
       Context ctx = new InitialContext();
       Object temp = ctx.lookup("ejb/entity/BMP/FileBMP");
       FileBMPRemoteHome fileRemoteHome = (FileBMPRemoteHome) PortableRemoteObject.narrow(temp,FileBMPRemoteHome.class);
      
       col = fileRemoteHome.findAll();
       }
       catch (ClassCastException e)
       {
       e.printStackTrace();
       }
       catch (NamingException e)
       {
       e.printStackTrace();
       }
       catch (FinderException e)
       {
       e.printStackTrace();
       }
       catch(RemoteException e)
       {
       e.printStackTrace();
       }
       while(col.hasMoreElements())
       {
       File obj = (File) col.nextElement();//EXCEPTION HERE*******
      
       addRow(obj.getVector());
       }
       }




      The exception I get:


      java.lang.ClassCastException
       at org.openbroad.j2ee.client.user.view.model.FilelistModel.getDataBMP(FilelistModel.java:105)
       at org.openbroad.j2ee.client.user.view.model.FilelistModel.<init>(FilelistModel.java:42)
       at org.openbroad.j2ee.client.user.view.Filelist.initComponents(Filelist.java:210)
       at org.openbroad.j2ee.client.user.view.Filelist.<init>(Filelist.java:56)
       at org.openbroad.j2ee.client.user.view.OpenBroad.jButton3ActionPerformed(OpenBroad.java:354)
       at org.openbroad.j2ee.client.user.view.OpenBroad.access$200(OpenBroad.java:30)
       at org.openbroad.j2ee.client.user.view.OpenBroad$3.actionPerformed(OpenBroad.java:104)
       at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
       at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
       at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
       at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
       at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
       at java.awt.Component.processMouseEvent(Component.java:5100)
       at java.awt.Component.processEvent(Component.java:4897)
       at java.awt.Container.processEvent(Container.java:1569)
       at java.awt.Component.dispatchEventImpl(Component.java:3615)
       at java.awt.Container.dispatchEventImpl(Container.java:1627)
       at java.awt.Component.dispatchEvent(Component.java:3477)
       at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
       at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
       at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
       at java.awt.Container.dispatchEventImpl(Container.java:1613)
       at java.awt.Window.dispatchEventImpl(Window.java:1606)
       at java.awt.Component.dispatchEvent(Component.java:3477)
       at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
       at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
       at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)