簡體   English   中英

錯誤:令牌上的語法錯誤,錯位的構造(s)

[英]Error: Syntax error on token(s), misplaced construct(s)

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]錯誤:令牌上的語法錯誤,錯位的構造(s)

我一直收到這個錯誤,不知道如何修復它。 我也得到錯誤構造函數Pet(java.lang.String)是未定義的

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

你忘記了構造函數調用中的括號( new ArrayList<Pet>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM