when i am trying to use delete button on my frame it is showing such exception and stack trace is here

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at MyFrame.actionPerformed(AcctHld.java:225)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
at java.awt.Component.processMouseEvent(Component.java:6099)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3287)
at java.awt.Component.processEvent(Component.java:5864)
at java.awt.Container.processEvent(Container.java:2109)
at java.awt.Component.dispatchEventImpl(Component.java:4460)
at java.awt.Container.dispatchEventImpl(Container.java:2167)
at java.awt.Component.dispatchEvent(Component.java:4286)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4465)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4129)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4059)
at java.awt.Container.dispatchEventImpl(Container.java:2153)
at java.awt.Window.dispatchEventImpl(Window.java:2554)
at java.awt.Component.dispatchEvent(Component.java:4286)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)

and my code for delete button is

else if(o.equals(bDelete)){
try {
	    int accountno=(Integer)mAccthld.getValueAt(tAcctHld.getSelectedRow(),0);
 	 mAccthld.removeRow(tAcctHld.getSelectedRow());
	    			
	   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DRIVER=Microsoft Access DRIVER (*.mdb);DBQ=fddata.mdb");
PreparedStatement ps=con.prepareStatement("delete from accthld where AccountNo=?");		 ps.setInt(1,accountno);
		 int s=ps.executeUpdate();		        
                  System.out.println(s);
			con.close();
	    		}
	    	catch(Exception ex){
	    	 ex.printStackTrace();
	    		}
						 
	    		
	    	}

u are type-casting a string value into integer one. try "parsing"
i.e

int accountno=Integer.parseInt(mAccthld.getValueAt(tAcctHld.getSelectedRow(),0));

i got this error when i used integer.parseint method
symbol : method parseInt(java.lang.Object)
location: class java.lang.Integer
int accountno=(Integer.parseInt(mAccthld.getValueAt(tAcctHld.getSelectedRow(),0)));
^

This article has been dead for over six months. Start a new discussion instead.