DeKay Posted July 14, 2007 Share Posted July 14, 2007 bonjour j'ai besoin d'aide avec un bou de code dans un programme: /** * @(#)Poker_main.java * * * @author * @version 1.00 2007/7/14 */ import java.util.Random; public class Poker { Player[] Players; boolean[][] cards; //Poker Game; /** * Creates a new instance of <code>Poker</code>. */ public Poker(String[] n) { Player[] Players = new Player[n.length]; for(int i=0; i<n.length; i++) { Players[i] = new Player(n[i]); } } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here if(args.length <= 0) System.out.println("No players specified."); else { Poker Game = new Poker(args); startRound(); } } public void startRound() { initCardDeck(); System.out.println(Players.length); for(int i=0; i<Players.length; i++) { giveHands(); } } public void initCardDeck() { cards = new boolean[13][3]; for(int i=0; i<Players.length; i++){ Players[i].cards = new int[2][2]; } } public void giveHands() { Random r = new Random(); for(int i=0; i<Players.length; i++) { for(int j=0; j<2; j++){ int valeur = 0 + r.nextInt(13 - 0 + 1); int couleur = 0 + r.nextInt(3 - 0 + 1); while(cards[valeur][couleur]) { valeur = 0 + r.nextInt(13 - 0 + 1); couleur = 0 + r.nextInt(3 - 0 + 1); } Players[i].cards[j][0]=valeur; Players[i].cards[j][1]=couleur; cards[valeur][couleur]=true; } } System.out.println("Hands: " + Players[1].cards); System.out.println("Hands: " + Players[2].cards); } } quand je l'execute cela me donne le message: Exception in thread "main" java.lang.NullPointerException at Poker.initCardDeck(Poker.java:47) at Poker.startRound(Poker.java:38) at Poker.main(Poker.java:33) si quelqu'un pourrait m'aider je serait très reconnaissant, merci beaucoup :) Link to comment Share on other sites More sharing options...
serik Posted July 14, 2007 Share Posted July 14, 2007 Déjà pour moi y'a ça qui ne va pas : Poker Game = new Poker(args); startRound(); Tu appelles startRound(), qui n'est pas une méthode static, sur aucun objet. tu devrais essayer "Game.startRound();" Après, pour ton NullPointerException, si il ne vient pas de là, il va falloir que tu nous forunisses ta class Player. Link to comment Share on other sites More sharing options...
DeKay Posted July 14, 2007 Author Share Posted July 14, 2007 vi j'ai déja essayer de mettre Game.startRound(); mais ça ne fontionne toujours pas ... voici la classe player: public class Player { String name; int bank; int[][] cards; public Player(String n) { name=n; bank=1000; System.out.println("Created player " + name + " with a bank of " + bank); } void setBank(int a) { bank+=a; System.out.println(name + "'s bank is now at " + bank); } } Link to comment Share on other sites More sharing options...
DeKay Posted July 14, 2007 Author Share Posted July 14, 2007 j'ai trouvé mon erreur, merci quand même :) Link to comment Share on other sites More sharing options...
LukeSkyPator Posted July 15, 2007 Share Posted July 15, 2007 Et quelle fut elle ? LSP, le manchot qui prône le partage pour tous Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.