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

GWT et Vaadin Java Discussion :

Initialiser une List


Sujet :

GWT et Vaadin Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 83
    Par défaut Initialiser une List
    Bonjour!

    Je commence en GWT avec quelques faibles notions de java.

    Je fais un appel à cette classe:

    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
    public class JeuDeCarte {
    	private List<Carte> carteRestante;
    	private List<Carte> carteJouer;
     
     
    	JeuDeCarte() {
    		initialiserJeuDeCarteRestante();
    	}
     
     
     
    	/**
             * Création et ajout des cartes au jeu carteRestante
             */
    	private void initialiserJeuDeCarteRestante() {
    		this.carteRestante.add(0, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_AS));
    		this.carteRestante.add(1, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_ROI));
    		this.carteRestante.add(2, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_DAME));
    		this.carteRestante.add(3, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_VALET));
    		this.carteRestante.add(4, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_DIX));
    		this.carteRestante.add(5, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_NEUF));
    		this.carteRestante.add(6, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_HUIT));
    		this.carteRestante.add(7, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_SEPT));
    		this.carteRestante.add(8, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_SIX));
    		this.carteRestante.add(9, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_CINQ));
    		this.carteRestante.add(10, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_QUATRE));
    		this.carteRestante.add(11, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_TROIS));
    		this.carteRestante.add(12, new Carte(ConstantePoker.COULEUR_CARREAU, ConstantePoker.VALEUR_DEUX));
    		this.carteRestante.add(13, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_AS));
    		this.carteRestante.add(14, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_ROI));
    		this.carteRestante.add(15, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_DAME));
    		this.carteRestante.add(16, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_VALET));
    		this.carteRestante.add(17, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_DIX));
    		this.carteRestante.add(18, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_NEUF));
    		this.carteRestante.add(19, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_HUIT));
    		this.carteRestante.add(20, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_SEPT));
    		this.carteRestante.add(21, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_SIX));
    		this.carteRestante.add(22, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_CINQ));
    		this.carteRestante.add(23, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_QUATRE));
    		this.carteRestante.add(24, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_TROIS));
    		this.carteRestante.add(25, new Carte(ConstantePoker.COULEUR_TREFLE, ConstantePoker.VALEUR_DEUX));
    		this.carteRestante.add(26, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_AS));
    		this.carteRestante.add(27, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_ROI));
    		this.carteRestante.add(28, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_DAME));
    		this.carteRestante.add(29, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_VALET));
    		this.carteRestante.add(30, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_DIX));
    		this.carteRestante.add(31, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_NEUF));
    		this.carteRestante.add(32, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_HUIT));
    		this.carteRestante.add(33, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_SEPT));
    		this.carteRestante.add(34, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_SIX));
    		this.carteRestante.add(35, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_CINQ));
    		this.carteRestante.add(36, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_QUATRE));
    		this.carteRestante.add(37, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_TROIS));
    		this.carteRestante.add(38, new Carte(ConstantePoker.COULEUR_PIQUE, ConstantePoker.VALEUR_DEUX));
    		this.carteRestante.add(39, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_AS));
    		this.carteRestante.add(40, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_ROI));
    		this.carteRestante.add(41, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_DAME));
    		this.carteRestante.add(42, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_VALET));
    		this.carteRestante.add(43, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_DIX));
    		this.carteRestante.add(44, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_NEUF));
    		this.carteRestante.add(45, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_HUIT));
    		this.carteRestante.add(46, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_SEPT));
    		this.carteRestante.add(47, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_SIX));
    		this.carteRestante.add(48, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_CINQ));
    		this.carteRestante.add(49, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_QUATRE));
    		this.carteRestante.add(50, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_TROIS));
    		this.carteRestante.add(51, new Carte(ConstantePoker.COULEUR_COEUR, ConstantePoker.VALEUR_DEUX));
    	}
     
    	public List<Carte> getCarteRestante() {
    		return carteRestante;
    	}
     
    	public void setCarteRestante(List<Carte> carteRestante) {
    		this.carteRestante = carteRestante;
    	}
     
    	public List<Carte> getCarteJouer() {
    		return carteJouer;
    	}
     
    	public void setCarteJouer(List<Carte> carteJouer) {
    		this.carteJouer = carteJouer;
    	}
    }
    depuis une autre classe j'ai un NullPointerException sur la première ligne de la méthode initialiserJeuDeCarteRestante.

    J'avoue ne pas bien comprendre pourquoi.

    Je vous remercie par avance.

    Jpa75

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2009
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France, Bas Rhin (Alsace)

    Informations forums :
    Inscription : Mars 2009
    Messages : 36
    Par défaut
    NullPointerException tu l'a quand tu essaye d'utiliser un objet non initialisé.
    Dans ton cas "carteRestante" est null.
    Il faut faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private List<Carte> carteRestante = new ArrayList<Carte>();

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    83
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 83
    Par défaut
    Effectivement... Quel nul je fais... ^_^

    Merci.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Comment ré-initialiser une liste déroulante ?
    Par jeje22 dans le forum Access
    Réponses: 5
    Dernier message: 03/06/2009, 21h32
  2. Initialiser une liste dans une strucuture
    Par Invité dans le forum SL & STL
    Réponses: 9
    Dernier message: 13/12/2007, 22h46
  3. Comment initialiser une liste déroulante ?
    Par sergoi dans le forum Struts 1
    Réponses: 5
    Dernier message: 12/07/2007, 11h35
  4. Comment initialiser une liste dans la méthode reset()
    Par don'de dans le forum Struts 1
    Réponses: 10
    Dernier message: 19/03/2007, 21h17
  5. Comment initialiser une liste de composants avec une boucle ?
    Par EricSid dans le forum Composants VCL
    Réponses: 5
    Dernier message: 06/04/2005, 18h46

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