File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 Murach's Java Servlets and JSP this week in the Servlets 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: 37901
    
  22
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?
 
Consider Paul's rocket mass heater.
 
subject: ClassCastException: java.util.Hashtable
 
Similar Threads
Dependency INjection through Annotations
SCJP1.4 : Confusion in equals() method
.MappingException
session time out issue it is not get expired in any way
Sending http POST Data and XML