if (jTable1.getSelectedRow() >= 0) {
String descricao = JOptionPane.showInputDialog(null, "Nova Descricao", "Descricao", JOptionPane.INFORMATION_MESSAGE);
if (descricao != null && !descricao.trim().isEmpty()) {
int row = jTable1.getSelectedRow();
Cliente p = dtm.getProduto(row);
//crio novo objeto para alteracao
Cliente pUpdate = new Cliente();
pUpdate.setCodigo(p.getCodigo());
pUpdate.setNome(p.getNome());
pUpdate.setCidade(p.getCidade());
pUpdate.setSexo(p.getSexo());
new ClienteDao().Atualizar(pUpdate);
dtm.updateRow(pUpdate, row);
}
} else {
JOptionPane.showMessageDialog(null, "Selecione a linha q deseja alterar", "Alterar", JOptionPane.WARNING_MESSAGE);
}
O Erro:
run:
12/03/2012 21:44:18 Principal jButton7ActionPerformed
GRAVE: null
java.lang.NullPointerException
at Principal.AlterarTable(Principal.java:345)
at Principal.jButton7ActionPerformed(Principal.java:269)
at Principal.access$600(Principal.java:11)
at Principal$7.actionPerformed(Principal.java:92)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6290)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6055)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4653)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:648)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:621)
at java.awt.EventQueue$2.run(EventQueue.java:619)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Não está aparecendo nenhum erro no código, mas na hora que executo acontece o erro citado acima.
Pessoal fiz os teste o código está dando erro nesta linha
Erro da linha 275
13/03/2012 07:53:49 Principal jButton7ActionPerformed
GRAVE: null
java.lang.NullPointerException
at Principal.jButton7ActionPerformed(Principal.java:275)
at Principal.access$600(Principal.java:11)
at Principal$7.actionPerformed(Principal.java:92)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6290)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6055)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4653)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:648)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:621)
at java.awt.EventQueue$2.run(EventQueue.java:619)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Que é nesta linha:
p = dtm.getProduto(row); //na hora que recebe os dados da tabela
Código do botão inserir:
ClienteDao pd = new ClienteDao();
Cliente p = new Cliente();
try {
if (jTable1.getSelectedRow() >= 0) {
String descricao = JOptionPane.showInputDialog(null, "Nova Descricao", "Descricao", JOptionPane.INFORMATION_MESSAGE);
if (descricao != null && !descricao.trim().isEmpty()) {
int row = jTable1.getSelectedRow();
p = dtm.getProduto(row); // ESTÁ É A LINHA 275
//crio novo objeto para alteracao
Cliente pUpdate = new Cliente();
pUpdate.setCodigo(p.getCodigo());
pUpdate.setNome(p.getNome());
pUpdate.setCidade(p.getCidade());
pUpdate.setSexo(p.getSexo());
pd.Atualizar(pUpdate);
dtm.updateRow(pUpdate, row);
}
} else {
JOptionPane.showMessageDialog(null, "Selecione a linha q deseja alterar", "Alterar", JOptionPane.WARNING_MESSAGE);
}
} catch (Exception ex) {
Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
}