erreur java java.lang.ClassCastException
je recupère les données de la base en les mettant dans un vector mais en utilisant StockData
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
while (results.next()) {
if (!hasData) {
m_vector.removeAllElements();
hasData = true;
}
String pc = results.getString(1);
String imp = results.getString(2);
String com = results.getString(3);
String ncc = results.getString(4);
String article = results.getString(5);
java.util.Date date = results.getDate(6);
long montant = results.getLong(7);
m_vector.addElement(new StockData(pc, imp, com,ncc, article, date, montant));
} |
J'essaie de recuperer avec la mèthode
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
public Object getValueAt(int nRow, int nCol) {
if (m_vector==null) return null;
if (nRow < 0 || nRow>=getRowCount())
return "";
StockData row = (StockData)m_vector.elementAt(nRow);
switch (nCol) {
case 0: return row.m_pc;
case 1: return row.m_imp;
case 2: return row.m_com;
case 3: return row.m_ncc;
case 4: return row.m_article;
case 5: return row.m_date;
case 6: return row.m_montant;
}
return "";
} |
Lors de l'éxécution il me ramène un message d'erreur
java.lang.ClassCastException
at Bd.Table.model.StockTableData.getValueAt(StockTableData.java:165)
et cette erreur pointe sur
Code:
1 2
|
StockData row = (StockData)m_vector.elementAt(nRow); |
C'est pourtant la même classe StockData que j'utilise pour inserer dans le vector donc je me comprends pas pourquoi cette erreur