Olá, pessoal!
Estou fazendo um cadastro simples de cidade, onde aparece para cadastro o nome da cidade (JTextField) e o estado (JComboBox).
Quando tento fazer a inserção dos dados dá o seguinte erro:
Exception in thread “AWT-EventQueue-0” java.lang.ClassCastException: java.lang.String at br.com.sstintas.Cidade$1.actionPerformed(Cidade.java:191)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
a linha 191 é a seguinte:
String sel = "Insert into cidade (id_cidade, estado_id_estado, nome_cidade) values('"+null+"','"+((PegarDados)cbEstado.getItemAt(cbEstado.getSelectedIndex())).getEstado_id()+"', '"+tfNomeCidade.getText()+"')";
Esse insert está dentro de um JButton.
Gostaria de alguma dica para resolver esse problema.
Obrigada!