Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7657441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:02:04+00:00 2026-05-31T13:02:04+00:00

I am typecasting the object to a bean class ,which in turn gives me

  • 0

I am typecasting the object to a bean class ,which in turn gives me a exception ClassCastException,i am not getting the issue behind this.

 Hashtable listEvent = getEvents(label1.getText(), str);

  Enumeration events = listEvent.keys();
   while (events.hasMoreElements()) {
    String key = (String) events.nextElement();

    if (key.equals(label1.getText())) {

       Vector object = (Vector) listEvent.get(key);

       Enumeration hashtable = listEvent.keys();
        while (hashtable.hasMoreElements()) {
          String keys = (String) hashtable.nextElement();
           if (keys.equals(label1.getText())) {

  Vector data = (Vector) listEvent.get(keys);
       for (int i = 0; i < data.size(); i++) {
      EventsBean bean1 = (EventsBean) data.elementAt(i);

I get an error while the running the application for typecasting to EventsBean.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:02:06+00:00Added an answer on May 31, 2026 at 1:02 pm

    First of all, if you used generic collections rather than raw types (Map<String, List<EventsBean>> instead of Hashtable), those errors would be caught by the compiler.

    Forget about Vector, Hashtable and Enumeration. They should not be used anymore since Java 1.2.

    And finally, why are you iterating on the hash table keys, instead of looking up the value directy?

    Instead of

    Enumeration events = listEvent.keys();
    while (events.hasMoreElements()) {
        String key = (String) events.nextElement();
        if (key.equals(label1.getText())) {
           Vector object = (Vector) listEvent.get(key);
    

    Just use

    Vector object = (Vector) listEvent.get(label1.getText());
    

    Now to answer your question: if you get a ClassCastException, it means that the objects stored in the collection are not what you think they are. Check the code which fills the collection. (and switch to generic, modern collections)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with either typecasting or object scope. I'm getting an uncaught
Any ideas on the correct method of typecasting an Object out of a getAttribute
This would be very handy as typecasting gets boring fast.
How costly is Object Typecasting in terms of performance? Should I try to avoid
Possible Duplicate: Perfomance of TypeCasting How expensive is it to cast as object as
I have 2 overloaded C# functions like this: private void _Insert(Hashtable hash, string tablename,
I have a custom class object in PHP named product : final class product
Worked fine before I threw it into a class. Any help for resolving this
I encountered this during object-relational mapping while creating a row mapper (to map a
Let's say there is a library function called get_pack() which returns a Pack object:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.