错误:令牌上的语法错误,错位的构造(s)

时间:2013-12-08 17:05:18

标签: java

import java.util.*;
import java.io.*;

public class ReadPets
{
public static void main (String[] args)
{

ArrayList <Pet> petList = new ArrayList <Pet>;
Scanner inFile = null;
String name;
Pet p;
try
{
  inFile = new Scanner
    (new FileInputStream ("pets.txt"));
}

catch(FileNotFoundException e)
{
  System.out.println("problem opening file.");
  System.exit(0);
}
while (inFile.hasNextLine())
{
  name = inFile.NextLine();
  p = newPet(name);
  petList.add(p);
}
inFile.close();
}
} 

    1 error found:

文件:C:\ Users \ remixt \ Desktop \ java \ ReadPets.java [line:9] 错误:令牌上的语法错误,错位的构造

我一直收到这个错误,不知道如何修复它。 我也得到错误构造函数Pet(java.lang.String)未定义

2 个答案:

答案 0 :(得分:2)

ArrayList <Pet> petList = new ArrayList <Pet>();

答案 1 :(得分:0)

您忘记了构造函数调用中的括号(new ArrayList<Pet>