HELP ...DONT UNDERSTAND Error
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)