【问题标题】:Error: Syntax error on token(s), misplaced construct(s)错误:令牌上的语法错误,错误的构造
【发布时间】:2013-12-08 17:05:18
【问题描述】:
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 [行:9] 错误:令牌的语法错误,错误的构造

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

【问题讨论】:

    标签: java


    【解决方案1】:
    ArrayList <Pet> petList = new ArrayList <Pet>();
    

    【讨论】:

      【解决方案2】:

      您忘记了构造函数调用中的括号 (new ArrayList&lt;Pet&gt;)

      【讨论】:

        猜你喜欢
        • 2015-02-24
        • 1970-01-01
        • 1970-01-01
        • 2013-07-16
        • 1970-01-01
        • 1970-01-01
        • 2013-05-20
        • 1970-01-01
        • 2014-03-02
        相关资源
        最近更新 更多