构造函数中错误的构造

时间:2015-06-17 21:40:26

标签: java

为什么会出现这些错误?我把它们放在评论中...... eclipse正在给我这些错误,我仍然无法理解为什么......甚至在谈论一个布尔值而我看不到......有人会说些什么......

public class GameInit 
{
 private static  int   playerNo;
// ArrayList<Integer> players = new ArrayList<Integer> ();
 Map <Integer, String> player = new HashMap<Integer, String>();


 public GameInit()
 {
  int firsthalf;
  int secondhalf;    
  firsthalf = playerNo/2;
  secondhalf = playerNo - (playerNo/2);

 for(int i = 0; i < firsthalf; i++)
 {
    player.put<i, "Human">; //syntax error on tokens, delete these tokens??? 
 }

 for(int j = firsthalf; j < secondhalf; j++)//syntak error on tokens,  misplaced construct(s) ????
 {
     player.put<j, "Alien">;//error: multiple markers at this line:cannot convert from bool to String? ehhrrrmm...where is the boolean??? 
 }


 }

1 个答案:

答案 0 :(得分:1)

我认为您正在尝试访问您的方法put而您正在使用2个参数,因此您必须更改<> ()。由此:

player.put<i, "Human">;

到此:

player.put(i, "Human");

我希望它会对你有所帮助!