gpt4 book ai didi

java - 初始化 ArrayList 时出错

转载 作者:行者123 更新时间:2023-11-29 03:49:42 26 4
gpt4 key购买 nike

public class driver 
{
private static ArrayList<String> arrayList ;
TownBankRecord TBR = new TownBankRecord();
ArrayList<Record> TBList = new ArrayList<Record>();

public void getDate()
{
try
{

BufferedReader br = new BufferedReader (new FileReader ("data/bank-data.csv"));
String line= " ";
int tokenCount=0;
//BankRecord bank= new BankRecord();

while((line=br.readLine())!=null)
{
if (!line.equals(","))
{
StringTokenizer st = new StringTokenizer(line,",");
while (st.hasMoreTokens())
{
arrayList.add(st.nextToken());
tokenCount++;
}
}

if (tokenCount==11)
{
er = new TownBankRecord(arrayList);
TBList.add(er);

tokenCount=0;
}
}
}
catch (FileNotFoundException ex)
{
System.out.println(ex.getMessage());
}
catch (IOException e)
{
System.err.println("Caught IOException: "
+ e.getMessage());

}
}
}

以上代码从 CSV 文件中读取。我使用了一个标记器,它从每一行获取标记,然后将它们传输到字符串的 ArrayList。然后将 ArrayList 传输到 TownBankRecord 的对象 er,然后最终传输到 TBlist(Record 数据类型)。呃,我有以下错误:

cannot find symbol
symbol: variable er
location: class nidhin.driver.

有什么想法吗?

最佳答案

您永远不会将 er 声明为变量。您也不要使用您声明的类字段 TBR。这些是相同的吗?

关于java - 初始化 ArrayList 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9382309/

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