Java错误---找不到符号符号:构造函数(似乎是新关键字)

时间:2015-01-31 17:32:20

标签: java

初学者提问,因为这是我第一次尝试使用Java编程。

我有一个文件夹,其中包含我的程序Program.java和一个名为football的文件夹,用于保存我的程序包。它包含文件football/Team.javafootball/Game.java

以下是我的文件内容:

Program.java

import football.*;
public class Program{
    public static void main(){
        Team homeTeam=new football.Team("MIN","Minnesota","Vikings");
        Team awayTeam=new football.Team("MIN","Minnesota","Vikings");
        Game game=new football.Game(homeTeam,awayTeam);
    }
}

football/Game.java

package football;
public class Game{
    public static void Game(Team homeTeam,Team awayTeam){

    }
}

football/Team.java

package football;
public class Team{
    public static void Team(String abbr, String city, String mascot){

    }
}

我试图通过在终端javac Program.java中运行来编译我的程序,我得到了:

Program.java:4: cannot find symbol
symbol  : constructor Team(java.lang.String,java.lang.String,java.lang.String)
location: class football.Team
        Team homeTeam=new football.Team("MIN","Minnesota","Vikings");
                      ^

有人能告诉我这段代码出错了吗?这里new运算符出了什么问题?

谢谢!

1 个答案:

答案 0 :(得分:3)

您的Team(和Game)构造函数使用static关键字和返回类型(即作为方法,而不是构造函数)声明,请将其更改为:

package football;
public class Team{
  public Team(String abbr, String city, String mascot){
  }
}

非泛型类型的构造函数采用表单(来自the docs):

modifiers SimpleTypeName(FormalParameters)

我还建议您阅读The Java Tutorials: Providing Constructors for Your Classes