纸牌游戏运行异常
恳请各位老师和大神的指点,谢谢!
我的纸牌代码总是报错:Exception in thread "main" java.lang.StackOverflowError
at CardsGame.Player.<init>(Player.java:20) 后面重复很多遍这个
错误指向源代码如下(创建两名玩家那里,加粗加下划线了):
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>();
}
//创建两名玩家
public Player player1 = new Player("1","wangxin");
public Player player2 = new Player("2","zhangxu");
public void TwoPlayer(){
System.out.println("两名玩家创建完成:");
System.out.println(player1.id +":" +player1.name +" " +player2.id +":" +player2.name);
}
}