Em algum lugar de um módulo do meu sistema está dando essa Exception, o problema é que no Stacktrace não tem como saber onde está o problema (não tem aquele: caused by), eu só sei que é em uma JTable, talvez no AbstractTableModel dela, mas não sei como resolver isso.
Parece que é informado algum objeto que não pode ser convertido para Date.
A coluna 1 é um Date e a coluna 2 é um Date que é renderizado para data/hora, então nem dá para saber em qual coluna é, vejam que coloquei um catch nas duas colunas mas não resolveu.
java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at javax.swing.JTable$DateRenderer.setValue(Unknown Source)
at javax.swing.table.DefaultTableCellRenderer.getTableCellRendererComponent(Unknown Source)
at javax.swing.JTable.prepareRenderer(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
at javax.swing.plaf.ComponentUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at com.sikgraf.lib.contextmenu.MyEventQueue.dispatchEvent(MyEventQueue.java:29)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
public class BaixaProducaoTableModel extends AbstractTableModel {
private static final String[] COLUMN_NAME = new String[]{"Id", "Data", "Hora", "Produzida", "Perdida", "Valor Baixa", "Contador", "Operador-1", "Operador-2"};
private static final Class[] COLUMN_TYPE = {Integer.class, Date.class, Date.class, Double.class, Double.class, Double.class, String.class, String.class, String.class};
public static final int[] COLUMN_WIDTH = {60, 80, 80, 100, 100, 100, 200, 200, 200};
ArrayList<BaixaProducao> lista;
public BaixaProducaoTableModel(ArrayList<BaixaProducao> lista) {
if (lista == null) {
lista = new ArrayList<BaixaProducao>();
}
this.lista = lista;
}
public int getRowCount() {
return (this.lista == null ? 0 : this.lista.size());
}
public int getColumnCount() {
return BaixaProducaoTableModel.COLUMN_TYPE.length;
}
@Override
public Class getColumnClass(int col) {
return COLUMN_TYPE[col];
}
@Override
public boolean isCellEditable(int row, int col) {
if (col > 0) {
return false;
} else {
return false;
}
}
@Override
public String getColumnName(int column) {
return COLUMN_NAME[column];
}
public Object getValueAt(int rowIndex, int columnIndex) {
BaixaProducao item = null;
try {
item = (BaixaProducao) this.lista.get(rowIndex);
} catch (java.lang.IndexOutOfBoundsException ex) {
return "";
}
switch (columnIndex) {
case 0:
return item.getId();
case 1:
return item.getDataBaixa();
case 2:
return item.getHoraBaixa();
case 3:
return item.getQuantidadeProduzida();
case 4:
return item.getQuantidadePerdida();
case 5:
return item.getValor();
case 6:
return item.getFuncionario();
case 7:
return item.getOperador1();
case 8:
return item.getOperador2();
}
return "";
}
@Override
public void setValueAt(Object value, int row, int col) {
if (lista == null && lista.size() == 0) {
return;
}
BaixaProducao item = this.lista.get(row);
if (value == null) {
return;
}
switch (col) {
case 1:
Date dataBaixa = null;
try {
dataBaixa = (Date) value;
} catch (Exception ex) {
}
item.setDataBaixa(dataBaixa);
break;
case 2:
Date horaBaixa = null;
try {
horaBaixa = (Date) value;
} catch (Exception ex) {
}
item.setHoraBaixa(horaBaixa);
break;
case 3:
item.setQuantidadeProduzida((Double) value);
break;
case 4:
item.setQuantidadePerdida((Double) value);
break;
case 5:
item.setValor((Double) value);
break;
case 6:
item.setFuncionario((String) value);
break;
case 7:
item.setOperador1((String) value);
break;
case 8:
item.setOperador2((String) value);
break;
}
this.lista.set(row, item);
fireTableCellUpdated(row, col);
fireTableDataChanged();
}
public void setLista(ArrayList<BaixaProducao> lista) {
this.lista = lista;
fireTableDataChanged();
}
public void addItem(BaixaProducao item) {
if (lista == null) {
lista = new ArrayList<BaixaProducao>();
}
lista.add(item);
this.fireTableRowsInserted(lista.size(), lista.size());
fireTableDataChanged();
//System.out.println("Linha adicionada");
}
public ArrayList<BaixaProducao> getLista() {
return this.lista;
}
public BaixaProducao getItemAt(int index) {
return lista.get(index);
}
public void deleteItem(BaixaProducao item) {
int index = lista.indexOf(item);
lista.remove(item);
fireTableRowsDeleted(index, index);
}
public void deleteItemAt(int index) {
//int index = lista.indexOf(item);
lista.remove(index);
fireTableRowsDeleted(index, index);
}
public double getTotalProduzida() {
double total = 0.0;
if (lista != null && lista.size() > 0) {
for (int i = 0; i < lista.size(); i++) {
BaixaProducao baixa = lista.get(i);
total = total + baixa.getQuantidadeProduzida();
}
}
return total;
}
}
BaixaProducaoTableModel model = new BaixaProducaoTableModel(lista);
tbBaixa.setModel(model);
TableColumnModel cm = tbBaixa.getColumnModel();
int[] columnWidth = BaixaProducaoTableModel.COLUMN_WIDTH;
for (int i = 0; i < BaixaProducaoTableModel.COLUMN_WIDTH.length; i++) {
cm.getColumn(i).setPreferredWidth(columnWidth[i]);
}
cm.getColumn(1).setCellRenderer(new DateCellRenderer());
cm.getColumn(2).setCellRenderer(new TimeCellRenderer());
cm.getColumn(3).setCellRenderer(new DecimalRenderer("####0.00"));
cm.getColumn(4).setCellRenderer(new DecimalRenderer("####0.00"));
cm.getColumn(5).setCellRenderer(new MoneyRenderer());
tbBaixa.setDefaultRenderer(Integer.class, new IntegerRenderer());
O pior de tudo é que esse problema ocorre somente na máquina do cliente (que fica a 300km de mim), na minha máquina não acontece.
Alguém teria alguma luz sobre isso?