java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to javaapplication2.components.VopD
je suis toujours confronté au problème de casting
le model
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| public void setData(java.util.List<javaapplication2.components.VopD> dataList){
m_frm = new SimpleDateFormat("MM/dd/yyyy");
model.removeAllElements();
//Object[] values = dataList.getSelectedValues();
for (int i = 0; i<dataList.size(); i++) {
//outputListModel.addElement(values[i]);
model.addElement(new VopData(dataList.get(i).structure,
dataList.get(i).nature,
dataList.get(i).libelle,
dataList.get(i).objet,
dataList.get(i).date_deb,
dataList.get(i).date_fin,
dataList.get(i).montant,
dataList.get(i).paye));
}
// the table model is interested in changes of the rows
fireTableRowsInserted(model.size()-1, model.size()-1);
} |
classe pour récupérer des données de la base
Code:
1 2 3 4 5 6 7 8 9 10
| public class VopD {
public Structure structure;
public Nature nature;
public String libelle;
public String objet;
public Date date_deb;
public Date date_fin;
public Long montant;
public Long paye;
} |
classe correspondante à VopD mais pour formatter les données afin de les afficher
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| private IconData structure;
private Integer nature;
private String libelle;
private String objet;
private Date date_deb;
private Date date_fin;
private SmartLong montant;
private SmartLong paye;
private float progress;
public VopData(Structure structure,
Nature nature,
String libelle,
String objet,
Date date_deb,
Date date_fin,
Long montant,
Long paye){
this.structure = new IconData(getIcon(montant,paye), structure.getCode());
this.nature = nature.getCode();
this.libelle = libelle;
this.objet = objet;
this.date_deb = date_deb;
this.date_fin = date_fin;
this.montant = new SmartLong(montant);
this.nature = nature.getCode();
this.paye = new SmartLong(paye);
this.progress = (float)((paye/montant) * 100);
} |
la requête pour récuperer les données
Code:
1 2 3 4 5 6 7 8 9
|
private javaapplication2.components.VopModel model;
private java.util.List<javaapplication2.components.VopD> VopDataList;
private javax.persistence.Query VopDataQuery;
VopDataQuery = java.beans.Beans.isDesignTime() ? null : gestcomPUEntityManager.createQuery("select o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens,sum(e.montant) from Operation o, Ecriture e where o.code = e.operation.code and e.sens = 'C' group by o.code,o.libelle,o.objet,o.montant,o.datefin,o.datedeb,o.datesais,o.statut,o.structure,o.nature,e.sens");
VopDataList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : VopDataQuery.getResultList();
model = new javaapplication2.components.VopModel(VopDataList);
masterTable.setModel(model); |
et l'erreur:
Citation:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to javaapplication2.components.VopD
at javaapplication2.components.VopModel.setData(VopModel.java:90)
at javaapplication2.components.VopModel.<init>(VopModel.java:81)
at javaapplication2.view.F_Consul_Operation.initComponents(F_Consul_Operation.java:119)
at javaapplication2.view.F_Consul_Operation.<init>(F_Consul_Operation.java:28)
at javaapplication2.view.F_Consul_Operation$2.run(F_Consul_Operation.java:201)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
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)
BUILD SUCCESSFUL (total time: 3 seconds)