Results 1 to 7 of 7
Thread: HELP ...DONT UNDERSTAND Error
- 11-25-2010, 03:12 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
HELP ...DONT UNDERSTAND Error
PHP Code://this is my hash table function public void hashTable(String s, int randX) { int key1 = (randX % 9); int c = (randX % 5) + 1; int i = 0; Integer check; check = (Integer) hashtable.get(key1); if (isEmpty(check)) { hashtable.put(key1, s); } else{ System.out.println("is it empty?????" + isEmpty(check)); } } // this is my boolean check public static boolean isEmpty(Integer p) { boolean isnull = false; // System.out.println("ok here p is : " + p); //any variables you would need if (p == null) //{ { System.out.println("it is true"); isnull = true; } return isnull; }
for some reason once the boolean fails it gives me this error
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at HashFunc.hashTable(HashFunc.java:237)
at HashFunc.actionPerformed(HashFunc.java:166)
at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.jav a:6352)
at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
at java.awt.Component.processEvent(Component.java:611 7)
at java.awt.Container.processEvent(Container.java:208 5)
at java.awt.Component.dispatchEventImpl(Component.jav a:4714)
at java.awt.Container.dispatchEventImpl(Container.jav a:2143)
at java.awt.Component.dispatchEvent(Component.java:45 44)
at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4621)
at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4282)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4212)
at java.awt.Container.dispatchEventImpl(Container.jav a:2129)
at java.awt.Window.dispatchEventImpl(Window.java:2478 )
at java.awt.Component.dispatchEvent(Component.java:45 44)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 635)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
- 11-25-2010, 03:43 AM #2
I can't see what your hashtable variable is or what put() is supposed to do, but I can tell that put() is trying to accept 2 integer variables and is receiving an integer and a string ( hashtable.put(key1, s); ).
- 11-25-2010, 04:55 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
ok put() is accepting two variables. an int(key) and a string(item). the problem is on my boolean check " isEmpty()
whenever i fails it never goes true it just spits the error out.
// i used the inbuilt hash table function.
Hashtable hashtable = new Hashtable(9);
hashtable.put(key1, s);// this put is part of the lib.
- 11-25-2010, 05:30 AM #4
I think it's failing onput() is trying to accept 2 integer variables and is receiving an integer and a stringwithJava Code:check = (Integer) hashtable.get(key1);
Evidently that's a Hashtable<Integer, String> and the reference returned from get(...) can't be cast to an Integer.Java Code:ClassCastException: java.lang.String cannot be cast to java.lang.Integer
db
- 11-25-2010, 08:20 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
Ok so how do i fix it?
Thank you
- 11-25-2010, 08:27 PM #6
Member
- Join Date
- Nov 2010
- Posts
- 4
- Rep Power
- 0
also to make that an object i have to type cast it as (Integer) if not its not gonna work..
if have any other ideas pls lemme know thank you
- 11-26-2010, 09:43 AM #7
The solution depends upon wat does hashtable.get(key1) return ? does it return a valid value parsable to Integer ???? .
Why don't u use a Hashtable<Integer,Integer> instead.Last edited by Vinod Mukundan; 11-26-2010 at 11:33 AM.
_______________________________________________
give me beans .........
Similar Threads
-
i dont understand why i cant run my program please help
By kungfu in forum New To JavaReplies: 3Last Post: 07-28-2010, 02:49 PM -
8 questions I dont understand while studying for SCJP
By shankhas in forum Java CertificationReplies: 5Last Post: 05-19-2010, 07:53 AM -
Dont understand Return Statement.
By ocean in forum New To JavaReplies: 6Last Post: 10-22-2009, 12:06 PM -
Data Files - A problem that I dont understand :D
By Exhonour in forum New To JavaReplies: 7Last Post: 01-20-2009, 05:13 AM -
i don understand this error
By Deon in forum New To JavaReplies: 4Last Post: 01-12-2008, 10:03 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks