File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ClassCastException: java.util.Hashtable" Watch "ClassCastException: java.util.Hashtable" New topic

ClassCastException: java.util.Hashtable

Hariom Tiwari

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();
return true;

I have set values as follow:
Hashtable<String,Boolean> operations= new Hashtable<String, Boolean>();
operations.put("Review_DeleteQuote", true);
when I am trying to read it like
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

Joined: Oct 13, 2005
Posts: 46349
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:
subject: ClassCastException: java.util.Hashtable
It's not a secret anymore!