aspose file tools*
The moose likes Beginning Java and the fly likes ClassCastException: java.util.Hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ClassCastException: java.util.Hashtable" Watch "ClassCastException: java.util.Hashtable" New topic
Author

ClassCastException: java.util.Hashtable

Hariom Tiwari
Greenhorn

Joined: Jun 15, 2008
Posts: 10
Hi all,
I have to return true or false from a Map. I have extended the HastTable class for this.
Please see the below code snippet.
public class MapUtil<S,B> extends Hashtable<String, Boolean> {
public boolean get(String key){
Boolean isAvailable=(Boolean)super.get(key);
if(isAvailable!= null)
{
return isAvailable.booleanValue();
}
else{
return true;
}
}

}
I have set values as follow:
Hashtable<String,Boolean> operations= new Hashtable<String, Boolean>();
operations.put("Review_DeleteQuote", true);
remoteEvents.setOperations(operations);
when I am trying to read it like
CustomerProducts.setOperations(remoteEvents.getOperations());
it is throwing java.lang.ClassCastException: java.util.Hashtable exception

I have written setOperations() as below
public static void setOperations(Hashtable<String, Boolean> operations) {
CustomerProducts.operations = (MapUtil<String, Boolean> operations;
}

please let me know where I am doing mistake.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39428
    
  28
Please edit your post to use code tags, and also click the "Disable smilies in this post." box; both will make your post easier to read.

Read what object you are passing and what you are casting it to. I hope that will explain your problem. Why are you creating the MapUtil class and not using it as a parameter?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassCastException: java.util.Hashtable