javafx - 线程“JavaFX 应用程序线程”中的 JAVAFX 异常
问题描述
当按下“Page-down”按钮时,我试图向表中添加 10 条记录,按下“向下箭头”也是如此。在尝试添加更多记录时,我不断收到异常错误。我为每个表使用游标映射。
this.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent event) {
switch (event.getCode()){
case PAGE_DOWN:
try {
if (resultSet.getRow() == numberOfRows) break;
if (((CanvasTableView) event.getSource()).getSelectionModel().getSelectedCells().get(0).getRow() > resultSet.getRow() - 17) {
Object object = table.getSelectionModel().selectedItemProperty().get(); // get the focus cell
int index = table.getSelectionModel().selectedIndexProperty().get(); // get the focus cell
int cursor_index = buffer_paging.get(table); //cursor index
resultSet.absolute(cursor_index);
System.out.println("Row: " + resultSet.getRow());
ArrayList<Row> data = dataBaseArrayListByNumber(rs, rs.getMetaData().getColumnCount(), 17,cursor_index);
table.getItems().addAll(data);
table.refresh();
System.out.println("Fuck yuval: " + ((CanvasTableView) event.getSource()).getSelectionModel().getSelectedCells().get(0).getRow());
buffer_paging.put(table, cursor_index+10);
System.err.println("Row: " + resultSet.getRow());
System.out.println(index);
}
}
catch (Exception e) {
e.printStackTrace();
}
break;
case PAGE_UP: System.err.println("Page up is pressed"); break;
case DOWN:
try {
if (resultSet.getRow() == numberOfRows) break;
int focus_cell = ((CanvasTableView) event.getSource()).getSelectionModel().getSelectedCells().get(0).getRow();
int cursor_index = buffer_paging.get(table); //cursor index
int rowNumber = table.getItems().size();
if (focus_cell == rowNumber-1 || focus_cell== rowNumber){
ArrayList<Row> data = dataBaseArrayListByNumber(rs, rs.getMetaData().getColumnCount(), 1,cursor_index);
table.getItems().addAll(data);
table.refresh();
int new_cursor = cursor_index+1;
buffer_paging.put(table, new_cursor);
}
}
catch (Exception e) {
e.printStackTrace();
}
break;
}
});
例外:
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index 16 out of bounds for length 16
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:373)
at java.base/java.util.ArrayList.get(ArrayList.java:425)
at javafx.base/com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:89)
at javafx.base/com.sun.javafx.collections.VetoableListDecorator.get(VetoableListDecorator.java:306)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Node.processCSS(Node.java:9537)
at javafx.graphics/javafx.scene.Scene.doCSSPass(Scene.java:569)
at javafx.graphics/javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2471)
at javafx.graphics/com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:413)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:412)
at javafx.graphics/com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:439)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:563)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:543)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:536)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:342)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:830)
我添加数据的功能:
private ArrayList dataBaseArrayListByNumber(ResultSet resultSet, int columnCount,int count,int cursor_index) throws SQLException {
ArrayList data = new ArrayList<>();
resultSet.absolute(cursor_index+1);
while (count>0&& resultSet.next()) {
HashMap<String, Double> columnData = new HashMap<String, Double>();
for (int i = 1; i < columnCount + 1; i++) {
String s = String.valueOf(i);
double x = resultSet.getDouble(i);
columnData.put(String.valueOf(i), resultSet.getDouble(i));
}
Row row = new Row(columnData);
data.add(row);
count--;
}
return data;
}
任何人都知道为什么我不断收到这些异常?
解决方案
推荐阅读
- node.js - NodeJS - 全局变量的值没有改变
- excel - 根据订单偏好和可用性从表中选择值 - Excel 2016
- node.js - 连接在 docker 容器中运行的数据库 (MongoDB) 和后端 (nodejs)
- javascript - 为什么 v-for & axios 不一个个加载项目?
- python - CMake不断从cygwin python中获取Python,如何从windows安装的Python中获取
- c++ - 混合使用左值和右值的三元运算符的类型推导
- android - 如何将渐变定义为圆形progressBar
- c - 无法将伪代码转换为 C(HykSort 算法的 MPI)
- oh-my-zsh - 为什么卸载ohmyzsh后终端以'/Users/nicholas/.zshrc:source:75: no such file or directory:'开头?
- reactjs - 为什么我会得到“`key` is not a prop”。在反应?