IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JPA Java Discussion :

java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to javaapplication2.components.VopD


Sujet :

JPA Java

  1. #1
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut 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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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:
    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)

  2. #2
    Membre régulier
    Inscrit en
    Mai 2003
    Messages
    350
    Détails du profil
    Informations forums :
    Inscription : Mai 2003
    Messages : 350
    Points : 84
    Points
    84
    Par défaut
    j'ai essayer de faire court en affichant directement le contenu de la List
    et j'ai la même erreur.
    Apparemment la liste ne contient pas des données de type VopD.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    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();
    for (javaapplication2.components.VopD o : VopDataList) {
         System.out.println("Libellé :"+ o.libelle);
    }
    Je ne comprends pas dans la mesure où je l'ai declaré une liste de VopD
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private java.util.List<javaapplication2.components.VopD> VopDataList;

Discussions similaires

  1. java.lang.ClassCastException: $Proxy2 cannot be cast
    Par olivier57b dans le forum Java EE
    Réponses: 0
    Dernier message: 14/07/2010, 20h52
  2. Réponses: 1
    Dernier message: 26/04/2010, 11h03
  3. Réponses: 3
    Dernier message: 30/09/2009, 11h36
  4. ClassCastException: [Ljava.lang.Object et Liste
    Par lepetitjoe dans le forum Langage
    Réponses: 14
    Dernier message: 26/06/2008, 18h29
  5. java.lang.object cannot be resolved
    Par hammag dans le forum Servlets/JSP
    Réponses: 9
    Dernier message: 24/06/2007, 11h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo