紙牌游戲運(yùn)行異常
懇請(qǐng)各位老師和大神的指點(diǎn),謝謝!
我的紙牌代碼總是報(bào)錯(cuò):Exception in thread "main" java.lang.StackOverflowError
at CardsGame.Player.<init>(Player.java:20) 后面重復(fù)很多遍這個(gè)
錯(cuò)誤指向源代碼如下(創(chuàng)建兩名玩家那里,加粗加下劃線了):
public class Player {
String id;
String name;
public Set<Cards> twoCards ;//= new HashSet<Cards>();
public Player(){};
public Player(String id,String name){
this.id = id;
this.name = name;
this.twoCards = new HashSet<Cards>();
}
//創(chuàng)建兩名玩家
public Player player1 = new Player("1","wangxin");
public Player player2 = new Player("2","zhangxu");
public void TwoPlayer(){
System.out.println("兩名玩家創(chuàng)建完成:");
System.out.println(player1.id +":" +player1.name +" ?" +player2.id +":" +player2.name);
}
}