gpt4 book ai didi

java - 错误 : Syntax error on token(s), 结构错位

转载 作者:行者123 更新时间:2023-12-02 06:26:38 25 4
gpt4 key购买 nike

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]错误: token 语法错误,构造错误

我不断收到该错误,不知道如何解决。我还收到错误构造函数 Pet(java.lang.String) 未定义

最佳答案

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

关于java - 错误 : Syntax error on token(s), 结构错位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20456211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com