gpt4 book ai didi

java.lang.OutOfMemory错误: Java heap space error occured when repeat calling of a function

转载 作者:行者123 更新时间:2023-12-01 23:11:56 25 4
gpt4 key购买 nike

您好,我在重复调用按钮函数时遇到错误

java.lang.OutOfMemoryError: 重复调用函数时发生 Java 堆空间错误或重复调用按钮

这是函数代码

    static java.util.List<Book>books=ServiceFactory.getBookServiceImpl().findAllBook();

JTable getTable() {
String[] cols = {"No", "Call No", "Title", "Category",
"Author", "Publisher", "Price",
"Donar", "Remarks"};
Object[][] data = new Object[books.size()][200000];

//Create same data for the table.
int i=0;
for (Book book:books) {
data[i][0] = i+1;
data[i][1] = book.getCallNo();
data[i][2] = book.getName();
data[i][3] = book.getCategory_id().getName();
data[i][4] = book.getAuthor();
data[i][5] = book.getPublisher();
data[i][6] = book.getPrice();
data[i][7] = book.getFrom();
data[i][8] = book.getRemark();

i++;
}



DefaultTableModel tableModel = new DefaultTableModel(data, cols) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
};
JTable table = new JTable(tableModel);

这是执行按钮调用的函数

public void actionPerformed(ActionEvent e) {
if(e.getSource()==btnBook){
new BookReport().getReport();


}

}

这是错误

Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at java.util.Vector.<init>(Unknown Source)
at java.util.Vector.<init>(Unknown Source)
at javax.swing.table.DefaultTableModel.convertToVector(Unknown Source)
at javax.swing.table.DefaultTableModel.convertToVector(Unknown Source)
at javax.swing.table.DefaultTableModel.setDataVector(Unknown Source)
at javax.swing.table.DefaultTableModel.<init>(Unknown Source)

最佳答案

数组的第二个维度是列。您似乎使用了 9 列。所以尝试一下:

Object[][] data = new Object[books.size()][9];

关于java.lang.OutOfMemory错误: Java heap space error occured when repeat calling of a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21800573/

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