Jeu de l'oie

Hello5562 Messages postés 2 Date d'inscription mardi 20 septembre 2011 Statut Membre Dernière intervention 2 novembre 2012 - 2 nov. 2012 à 20:09
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 - 3 nov. 2012 à 19:16
Bonjour,

Je dois réaliser un jeu de l'oie.
Mais lorsque je veux initialiser toute mes cellules j'ai un nullPointerException :
protected void initBoard(){
System.out.println("init");
RegularCell reg ;
for(int i=0; i<=80; i++){
System.out.println("cell "+ i+ " créée");
reg = new RegularCell(i);
theCells[i]=  reg; //nullpointerException
}
int n= this.twoDicesThrow();
GooseCell oie1 = new GooseCell(9, theCells[9+n]);
GooseCell oie2 = new GooseCell(18, theCells[18+n]);
GooseCell oie3 = new GooseCell(27, theCells[27+n]);
GooseCell oie4 = new GooseCell(36, theCells[36+n]);
GooseCell oie5 = new GooseCell(45, theCells[45+n]);
GooseCell oie6 = new GooseCell(54, theCells[54+n]);
TrapCell piege = new TrapCell(31, 1000);
TrapCell piege2 = new TrapCell(52, 1000);
WaitCell attente = new WaitCell(19, 2);
TeleportationCell tele = new TeleportationCell(6, theCells[12]);
TeleportationCell tele2 = new TeleportationCell(42, theCells[30]);
TeleportationCell tele3 = new TeleportationCell(58, theCells[1]);
theCells[9]=oie1;
theCells[18]=oie2;
theCells[27]=oie3;
theCells[36]=oie4;
theCells[45]=oie5;
theCells[54]=oie6;
theCells[31]=piege;
theCells[52]=piege2;
theCells[19]=attente;
theCells[6]=tele;
theCells[42]=tele2;
theCells[58]=tele3;

}

sachant que la classe dans laquelle je suis est une classe abstraite, et que mon tableau et declaré au debut de cette classe.


Merci

1 réponse

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
3 nov. 2012 à 19:16
Salut,

Il ne suffit pas de déclarer le tableau, il faut l'initialiser :

RegularCell[] theCells = new RegularCell[81];


Toi, tu dois avoir ca je pense :

RegularCell[] theCells;
0
Rejoignez-nous