gpt4 book ai didi

java - 获取 ArrayIndexOutOfBoundsException : 3 >=3 when trying to export JTable contents to a text file

转载 作者:行者123 更新时间:2023-12-01 10:19:17 24 4
gpt4 key购买 nike

我目前正在尝试用 Java 为我在大学的一个项目编写一个财务程序。项目要求之一是将 JTable 数据导出到文本文件。这是我的代码(假设该表已填充)。

但是,当尝试写入文件时,我收到此错误:

java.lang.ArrayIndexOutOfBoundsException: 3 >= 3

关于我做错了什么的任何想法......

我最初遵循本指南:http://1bestcsharp.blogspot.co.uk/2015/04/java-io-how-to-export-jtable-data-to-txt-File-In-Java.html

但使用了不同的方法写入文件 ( https://www.caveofprogramming.com/java/java-file-reading-and-writing-files-in-java.html )

谢谢

本。

    try {
FileWriter fileWriter = new FileWriter(fileName);
BufferedWriter bw = new BufferedWriter(fileWriter);
System.out.println(tbl_Finance.getRowCount() + " " + tbl_Finance.getColumnCount());
for(int i = 0; i < tbl_Finance.getRowCount(); i++) {
for(int j = 0; i < tbl_Finance.getColumnCount(); j++) {
bw.write(tbl_Finance.getValueAt(i, j) + " ");
}
bw.write("\n_________\n");
}
bw.close();
JOptionPane.showMessageDialog(null, "Data Exported To " + fileName);
} catch(Exception ex) {
ex.printStackTrace();
}

最佳答案

改变

for(int j = 0; i < tbl_Finance.getColumnCount(); j++)

for(int j = 0; j < tbl_Finance.getColumnCount(); j++)

关于java - 获取 ArrayIndexOutOfBoundsException : 3 >=3 when trying to export JTable contents to a text file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35720480/

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