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

Persistance des données Java Discussion :

[JPox] NullPointerException ou pas !


Sujet :

Persistance des données Java

  1. #1
    Membre régulier
    Inscrit en
    Avril 2004
    Messages
    190
    Détails du profil
    Informations personnelles :
    Âge : 39

    Informations forums :
    Inscription : Avril 2004
    Messages : 190
    Points : 88
    Points
    88
    Par défaut [JPox] NullPointerException ou pas !
    Salut,

    J'ai problème trés bizarre! J'ai des classes sur lesquelles j'applique un code. Sur certaines ce code fonctionne et sur d'autres j'obtient cette erreur:
    Exception in thread "main" java.lang.NullPointerException
    at org.jpox.store.mapping.SingleFieldMapping.getString(SingleFieldMapping.java:230)
    at org.jpox.store.rdbms.fieldmanager.ResultSetGetter.fetchStringField(ResultSetGetter.java:84)
    at org.jpox.state.StateManagerImpl.replacingStringField(StateManagerImpl.java:2484)
    at Capitalisation.dossier.Responsables.jdoReplaceField(Responsables.java)
    at Capitalisation.dossier.Responsables.jdoReplaceFields(Responsables.java)
    at org.jpox.state.StateManagerImpl.replaceFields(StateManagerImpl.java:2625)
    at org.jpox.store.query.PersistentIDROF$1.fetchFields(PersistentIDROF.java:124)
    at org.jpox.state.StateManagerImpl.<init>(StateManagerImpl.java:423)
    at org.jpox.AbstractPersistenceManager.getObjectByAID(AbstractPersistenceManager.java:2026)
    at org.jpox.store.query.PersistentIDROF.getObjectByAID(PersistentIDROF.java:119)
    at org.jpox.store.query.PersistentIDROF.getObject(PersistentIDROF.java:92)
    at org.jpox.store.query.ForwardQueryResult.nextResultSetElement(ForwardQueryResult.java:127)
    at org.jpox.store.query.ForwardQueryResult$QueryResultIterator.next(ForwardQueryResult.java:199)
    at Capitalisation.dossier.sql.RespTx.afficher(RespTx.java:128)
    at Capitalisation.test.MainTest.main(MainTest.java:105)
    Pourtant les seuls choses qui diffèrent entre ces classes sont le nombre de paramètres. Alors j'ai regardé si y avait des types qui passaient pas, mais tous les types que j'utilise sont dans les classes qui marchent.

    Donc je vais vous donner les codes de 2 classes: une qui marche (offre.class) et une qui marche pas (contact.class).


    Offre.java
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    package Capitalisation.dossier;
     
    public class Offre {
     
    	/**
             *  
             * @uml.property name="nom" 
             */
    	private String nom;
     
    	private int id_projet;
    	private String id_offre;
     
    	/**
             *  
             * @uml.property name="nom"
             */
    	public String getNom() {
    		return nom;
    	}
     
    	/**
             *  
             * @uml.property name="nom"
             */
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
     
     
    	/**
             * @return Renvoie id_projet.
             */
    	public int getId_projet() {
    		return id_projet;
    	}
    	/**
             * @param id_projet id_projet à définir.
             */
    	public void setId_projet(int id_projet) {
    		this.id_projet = id_projet;
    	}
     
     
    	/**
             * @return Renvoie id_offre.
             */
    	public String getId_offre() {
    		return id_offre;
    	}
    	/**
             * @param id_offre id_offre à définir.
             */
    	public void setId_offre(String id_offre) {
    		this.id_offre = id_offre;
    	}
    }
    Contact.java
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    package Capitalisation.dossier;
     
    public class Contact {
     
    	/**
             *  
             * @uml.property name="nom" 
             */
    	private String nom;
     
    	private String id_contact;
    	private int id_client;
     
    	/**
             *  
             * @uml.property name="prenom" 
             */
    	private String prenom;
     
    	/**
             *  
             * @uml.property name="tel" 
             */
    	private String tel;
     
    	/**
             *  
             * @uml.property name="fax" 
             */
    	private String fax;
     
    	/**
             *  
             * @uml.property name="position" 
             */
    	private String position;
     
     
    	/**
             *  
             * @uml.property name="email" 
             */
    	private String email;
     
     
     
    	/**
             * 
             */
    	public Contact() {
    		super();
    	}
     
     
    	/**
             * @param nom
             * @param id_contact
             * @param id_client
             * @param prenom
             * @param tel
             * @param fax
             * @param position
             * @param email
             */
    	public Contact(String nom, String id_contact, int id_client,
    			String prenom, String tel, String fax, String position, String email) {
    		super();
    		this.nom = nom;
    		this.id_contact = id_contact;
    		this.id_client = id_client;
    		this.prenom = prenom;
    		this.tel = tel;
    		this.fax = fax;
    		this.position = position;
    		this.email = email;
    	}
     
    	/**
             * @return Renvoie id_client.
             */
    	public int getId_client() {
    		return id_client;
    	}
    	/**
             * @param id_client id_client à définir.
             */
    	public void setId_client(int id_client) {
    		this.id_client = id_client;
    	}
    	/**
             * @return Renvoie id_contact.
             */
    	public String getId_contact() {
    		return id_contact;
    	}
    	/**
             * @param id_contact id_contact à définir.
             */
    	public void setId_contact(String id_contact) {
    		this.id_contact = id_contact;
    	}
     
    	/**
             *  
             * @uml.property name="nom"
             */
    	public String getNom() {
    		return nom;
    	}
     
    	/**
             *  
             * @uml.property name="nom"
             */
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	/**
             *  
             * @uml.property name="prenom"
             */
    	public String getPrenom() {
    		return prenom;
    	}
     
    	/**
             *  
             * @uml.property name="prenom"
             */
    	public void setPrenom(String prenom) {
    		this.prenom = prenom;
    	}
     
    	/**
             *  
             * @uml.property name="tel"
             */
    	public String getTel() {
    		return tel;
    	}
     
    	/**
             *  
             * @uml.property name="tel"
             */
    	public void setTel(String tel) {
    		this.tel = tel;
    	}
     
    	/**
             *  
             * @uml.property name="fax"
             */
    	public String getFax() {
    		return fax;
    	}
     
    	/**
             *  
             * @uml.property name="fax"
             */
    	public void setFax(String fax) {
    		this.fax = fax;
    	}
     
    	/**
             *  
             * @uml.property name="position"
             */
    	public String getPosition() {
    		return position;
    	}
     
    	/**
             *  
             * @uml.property name="position"
             */
    	public void setPosition(String position) {
    		this.position = position;
    	}
     
    	/**
             *  
             * @uml.property name="email"
             */
    	public String getEmail() {
    		return email;
    	}
     
    	/**
             *  
             * @uml.property name="email"
             */
    	public void setEmail(String email) {
    		this.email = email;
    	}
    }
    Offre en jdo (dans package.jdo)
    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
    <class
            	  identity-type="application"
                  name="Offre"
                  objectid-class="Capitalisation.dossier.OffreIdKey">
                <field
                      name="id_offre"
                      primary-key="true">
                      <column
                         name="id_offre"/>
                </field>
                <field
                      name="nom"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column
                         length="45"
                         jdbc-type="VARCHAR"/>
                </field>
                <field
                      name="id_projet"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column jdbc-type="INTEGER"/>
                </field>
            </class>
    Contact en jdo (dans package.jdo)
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    <class
                  name="Contact"
                  identity-type="application"
                  objectid-class="Capitalisation.dossier.ContactIdKey"
                  detachable="false"
                  requires-extent="true">
                  <field
                      name="id_contact"
                      primary-key="true">
                      <column
                         name="id_contact"/>
                </field>
                <field
                      name="nom"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column
                         length="45"
                         jdbc-type="VARCHAR"/>
                </field>
                <field
                      name="prenom"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column
                         length="45"
                         jdbc-type="VARCHAR"/>
                </field>
                <field
                      name="tel"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column
                         length="10"
                         jdbc-type="VARCHAR"/>
                </field>
                <field
                      name="fax"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column
                         length="10"
                         jdbc-type="VARCHAR"/>
                </field>
                <field
                      name="position"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column
                         length="45"
                         jdbc-type="VARCHAR"/>
                </field>
                <field
                      name="email"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column
                         length="45"
                         jdbc-type="VARCHAR"/>
                </field>
                <field
                      name="id_client"
                      null-value="none"
                      primary-key="false"
                      persistence-modifier="persistent">
                   <column jdbc-type="INTEGER"/>
                </field>
            </class>
    OffreTx.java (classe contenant les requetes à la DB)
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
     
     
    package Capitalisation.dossier.sql;
     
    import java.util.Iterator;
    import java.util.List;
     
    import javax.jdo.PersistenceManager;
    import javax.jdo.Query;
    import javax.jdo.Transaction;
     
    import Capitalisation.dossier.Offre;
    import Connection.ConnectJpox;
     
    public class OffreTx {
    	public PersistenceManager pm;
    	public Transaction tx;
    	public Query q;
     
    	/**
             * 
             * @param pm
             * @param tx
             * @param q
             */
    	public OffreTx(PersistenceManager pm, Transaction tx, Query q) {
    		super();
    		this.pm = pm;
    		this.tx = tx;
    		this.q = q;
    	}
     
    	public OffreTx() {
    		super();
    		this.pm = (new ConnectJpox()).connectMoi();
    		this.tx = pm.currentTransaction();
    	}
     
    	/* ====================================== */
    	/* =============== SELECT =============== */
    	/* ====================================== */
     
    	/**
             * Renvoie la liste de tous les clients
             * @return
             */
    	public Iterator selectAll(){
     
    		/*Extent e = pm.getExtent(Responsables.class,true);
     
    		return e.iterator();*/
     
    		//Query q = pm.newQuery(Outil.class);
     
    		Query q = pm.newQuery("javax.jdo.query.SQL", "SELECT * FROM offre");
    		q.setClass(Offre.class);
     
    		List results = (List) q.execute();
    		return results.iterator(); 
     
    	    //Query q = pm.newQuery(Outil.class, "select * from outil");
    	    //Query q = pm.newNamedQuery(Outil.class, "selectAll_jdosql");
    	}
     
     
    	/* ====================================== */
    	/* ============= AFFICHAGE ============== */
    	/* ====================================== */
     
    	public void afficher(Iterator it){
    		while (it.hasNext()) {
    			   Offre offre = (Offre) it.next();
    			   System.out.println("Id Offre: " + offre.getId_offre());
    			   System.out.println("Nom: " + offre.getNom());
    			   System.out.println("Id Projet: " + offre.getId_projet());
    			}
    	}
     
     
     
    	/* === TRANSACTIONS === */
    	public void OuvrirTx(){
    		tx.begin();
    	}
     
    	public void FermerTx(){
    		tx.commit();
    	}
     
    	public void FermerQuery(){
    		q.closeAll();
    	}
    }
    ContactTx.java (classe contenant les requetes à la DB)
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    package Capitalisation.dossier.sql;
     
    import java.util.Iterator;
    import java.util.List;
     
    import javax.jdo.PersistenceManager;
    import javax.jdo.Query;
    import javax.jdo.Transaction;
     
    import Capitalisation.dossier.Contact;
    import Connection.ConnectJpox;
     
    public class ContactTx {
    	public PersistenceManager pm;
    	public Transaction tx;
    	public Query q;
     
    	/**
             * 
             * @param pm
             * @param tx
             * @param q
             */
    	public ContactTx(PersistenceManager pm, Transaction tx, Query q) {
    		super();
    		this.pm = pm;
    		this.tx = tx;
    		this.q = q;
    	}
     
    	public ContactTx() {
    		super();
    		this.pm = (new ConnectJpox()).connectMoi();
    		this.tx = pm.currentTransaction();
    	}
     
    	/* ====================================== */
    	/* =============== SELECT =============== */
    	/* ====================================== */
     
    	/**
             * Renvoie la liste de tous les clients
             * @return
             */
    	public Iterator selectAll(){
     
    		/* Extent e = pm.getExtent(Contact.class,true);
     
    		return e.iterator(); */
     
    		//Query q = pm.newQuery(Outil.class);
     
    		Query q = pm.newQuery("javax.jdo.query.SQL", "SELECT * FROM contact");
    		q.setClass(Contact.class);
     
    		List results = (List) q.execute();
    		return results.iterator(); 
     
    	    //Query q = pm.newQuery(Outil.class, "select * from outil");
    	    //Query q = pm.newNamedQuery(Outil.class, "selectAll_jdosql");
    	}
     
    	/* ====================================== */
    	/* ============= AFFICHAGE ============== */
    	/* ====================================== */
     
    	public void afficher(Iterator it){
    		while (it.hasNext()) {
    			Contact ct = (Contact) it.next();  //ERREUR ICI
    			   System.out.println("Id Contact: " + ct.getId_contact());
    			   System.out.println("Email: " + ct.getEmail());
    			   System.out.println("Fax: " + ct.getFax());
    			   System.out.println("Nom: " + ct.getNom());
    			   System.out.println("Position: " + ct.getPosition());
    			   System.out.println("Prenom: " + ct.getPrenom());
    			   System.out.println("Tel: " + ct.getTel());
    			   System.out.println("Id Client: " + ct.getId_client());
    			}
    	}
     
     
     
    	/* === TRANSACTIONS === */
    	public void OuvrirTx(){
    		tx.begin();
    	}
     
    	public void FermerTx(){
    		tx.commit();
    	}
     
    	public void FermerQuery(){
    		q.closeAll();
    	}
    }
    Code de test de Offre (dans le Main):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    //		 ==== TEST OFFRE ====		
    	 OffreTx TxOf = new OffreTx();
    		TxOf.OuvrirTx();
    		System.out.println("=== AFFICHAGE 1 ===");
    		TxOf.afficher(TxOf.selectAll());
    		TxOf.FermerTx();
    Code de test de Contact (dans le Main):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    // ==== TEST CONTACT ====		
    	ContactTx Txct = new ContactTx();
    		Txct.OuvrirTx();
    		System.out.println("=== AFFICHAGE 1 ===");
    		Txct.afficher(Txct.selectAll()); //ERREUR ICI
    		Txct.FermerTx();
    Voilà, désolé de vous mettre autant de code, mais je pense que celà est nécessaire pour arriver à comprendre mon erreur
    J'espère que vous serez pas trop décourager par autant de code. Ca fait 2 jours que je cherche pkoi j'ai cette erreur!!!

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    169
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 169
    Points : 113
    Points
    113
    Par défaut
    j'ai pas lu tout le code ..... mais c'est quoi la ligne 105 de ta méthode main ?

Discussions similaires

  1. NullPointerException pas de données
    Par maserati dans le forum JSF
    Réponses: 3
    Dernier message: 05/04/2012, 12h25
  2. [Security] @Autowired ne fonctionne pas -> NullPointerException
    Par Bourrine dans le forum Spring
    Réponses: 2
    Dernier message: 02/03/2011, 15h25
  3. NullPointerException, mais pas toujours :)
    Par Aurel35N dans le forum Composants
    Réponses: 1
    Dernier message: 30/06/2010, 15h14
  4. java.lang.NullPointerException que je ne trouve pas
    Par Raiden1234 dans le forum Général Java
    Réponses: 6
    Dernier message: 29/11/2008, 10h33
  5. [JPox] NullPointerException aprés un SELECT
    Par MinsK dans le forum Persistance des données
    Réponses: 3
    Dernier message: 05/07/2005, 13h46

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