[英]why it does not compile issue
A part of my project I have a class named Team and a class Game. 在项目的一部分中,我有一个名为Team的类和一个Game的类。 When I try to compile the following code, these errors are occurred.
当我尝试编译以下代码时,会发生这些错误。
Player allPlayers[] = new Player[10];
Syntax error on token ";", { expected after this token
令牌“;”上的语法错误,{预期在此令牌之后
public void addPlayer(Player p)
Syntax error on token ")", ;
令牌“)”上的语法错误,; expected after this token Syntax error on token "(", ; expected after this token
预期在此标记之后标记“(”,;上的语法错误;预期在此标记之后
and the same errors for all the methods declarations
并且所有方法声明都存在相同的错误
Source code of class team 班级团队的源代码
import java.io.*;
import java.util.*;
public class Team
{
rounds = 0;
private static final int cPlayers = 5; //Arithmos pektwn se kathe omada
//Constructor
public Game() {
............
}
Does it have to do anything with this? 它与此有关系吗?
You can only place this code in a code block. 您只能将此代码放在代码块中。 What you can do is
你能做的是
Player allPlayers[] = new Player[10];
{
allPlayers[0] = new Forward();
allPlayers[1] = new Forward();
allPlayers[2] = new Forward();
allPlayers[3] = new Defender();
allPlayers[4] = new Defender();
}
Or you can do 或者你可以做
Player[] allPlayers = { new Forward(), new Forward(), new Forward(),
new Defender(), new Defender(),
null, null, null, null, null };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.