- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我是 Java 新手,在运行应用程序时遇到错误。应用程序运行但是当按钮单击事件 createStudent(ActionEvent event)
被调用时显示错误。我正在粘贴完整的错误堆栈跟踪。
javafx.fxml.LoadException:
/home/user/IdeaProjects/JavaFxDemo/out/production/JavaFxDemo/resources/fxml/newStudent.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2571)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at dashboard.Controller.createStudent(Controller.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$49(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2566)
... 65 more
Caused by: java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.checkClosed(ResultSet.java:666)
at com.mysql.jdbc.ResultSet.next(ResultSet.java:7274)
at dashboard.AdmissionController.initialize(AdmissionController.java:168)
... 75 more
我检查了下面位置的fxml文件是否有问题,没有问题。
javafx.fxml.LoadException:
/home/user/IdeaProjects/JavaFxDemo/out/production/JavaFxDemo/resources/fxml/newStudent.fxml
请检查我的 Controller 文件
dashboard.Controller.java
package dashboard;
import java.io.IOException;
import java.net.URL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.IdentityHashMap;
import java.util.Observable;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import dashboard.StudentMaster;
import database.DatabaseAccess;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import java.sql.Connection;
public class Controller {
private Connection connection;
@FXML
private ResourceBundle resources;
@FXML
private URL location;
@FXML
private TableView<StudentMaster> studentTable;
@FXML
private TableColumn<StudentMaster, Integer> studID;
@FXML
private TableColumn<StudentMaster, String> studReg;
@FXML
private TableColumn<StudentMaster, String> stdAdm;
@FXML
private TableColumn<StudentMaster, String> stdName;
@FXML
private TableColumn<StudentMaster, String> stdClass;
@FXML
private TableColumn<StudentMaster, String> stdDiv;
@FXML
private TextField regBox;
@FXML
private TextField admBox;
@FXML
private TextField nameBox;
@FXML
private TextField classBox;
@FXML
private TextField divBox;
@FXML
private Button searchBtn;
@FXML
private Button createStudentBtn;
private ObservableList<StudentMaster> data;
public void buildData(String SQL)
{
data = FXCollections.observableArrayList();
try {
ResultSet rs = connection.createStatement().executeQuery(SQL);
while(rs.next())
{
StudentMaster studentData = new StudentMaster();
studentData.studentId.set(rs.getInt("student_id"));
studentData.stdClass.set(rs.getString("student_std"));
studentData.name.set(rs.getString("student_name"));
studentData.admNo.set(rs.getString("student_admn_no"));
studentData.regno.set(rs.getString("student_regno"));
studentData.stdDiv.set(rs.getString("student_div"));
data.add(studentData);
studentTable.setItems(data);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
@FXML
void initialize() {
assert studentTable != null : "fx:id=\"studentTable\" was not injected: check your FXML file 'dashboard.fxml'.";
assert studID != null : "fx:id=\"studID\" was not injected: check your FXML file 'dashboard.fxml'.";
assert studReg != null : "fx:id=\"studReg\" was not injected: check your FXML file 'dashboard.fxml'.";
assert stdAdm != null : "fx:id=\"stdAdm\" was not injected: check your FXML file 'dashboard.fxml'.";
assert stdName != null : "fx:id=\"stdName\" was not injected: check your FXML file 'dashboard.fxml'.";
assert stdClass != null : "fx:id=\"stdClass\" was not injected: check your FXML file 'dashboard.fxml'.";
assert stdDiv != null : "fx:id=\"stdDiv\" was not injected: check your FXML file 'dashboard.fxml'.";
DatabaseAccess newConnection = new DatabaseAccess();
connection = newConnection.startConnection();
String SQL = "Select * from student";
buildData(SQL);
newConnection.shutdown();
loadDataToTable();
}
private void loadDataToTable()
{
studID.setCellValueFactory(new PropertyValueFactory<StudentMaster, Integer>("studentId"));
studReg.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("regno"));
stdName.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("name"));
stdAdm.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("admNo"));
stdClass.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("stdClass"));
stdDiv.setCellValueFactory(new PropertyValueFactory<StudentMaster, String>("stdDiv"));
}
@FXML
void createStudent(ActionEvent event)
{
FXMLLoader fxmlLoader;
fxmlLoader = new FXMLLoader(getClass().getResource("/resources/fxml/newStudent.fxml"));
try {
Parent root1 = (Parent)fxmlLoader.load();
AdmissionController admissionController = fxmlLoader.getController();
admissionController.setStudentData(studentTable.getItems());
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
// stage.initStyle(StageStyle.UNDECORATED);
stage.setTitle("New Admission");
stage.setScene(new Scene(root1));
stage.show();
} catch (IOException e)
{
e.printStackTrace();
}
}
@FXML
void searchBtnClicked(ActionEvent event)
{
String name = nameBox.getText();
String regno = regBox.getText();
String admno = admBox.getText();
String stdClass = classBox.getText();
String SQL = "Select * from student where student_name like '"+name+"%'";
System.out.println(SQL);
DatabaseAccess newConnection = new DatabaseAccess();
connection = newConnection.startConnection();
buildData(SQL);
newConnection.shutdown();
loadDataToTable();
}
public void reloadStudentTable()
{
loadDataToTable();
}
}
dashboard.AdmissionController.java
package dashboard;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.input.InputMethodEvent;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import customlib.ExecuteSQL;
import dashboard.AvailableClasses;
import java.sql.ResultSet;
import java.sql.SQLException;
public class AdmissionController {
@FXML
private TextField nameBox;
@FXML
private ChoiceBox<String> classBox;
@FXML
private ChoiceBox<String> divBox;
@FXML
private TextField admBox;
@FXML
private TextField religionBox;
@FXML
private TextField casteBox;
@FXML
private TextArea addressBox;
@FXML
private DatePicker dobBox;
@FXML
private ChoiceBox<?> sexBox;
@FXML
private Button resetBtn;
@FXML
private Button cancelBtn;
@FXML
private Button doneBtn;
@FXML
void cancelBtnClicked(ActionEvent event)
{
// GET the current node of the event
Node node = (Node)event.getSource();
Stage stage = (Stage)node.getScene().getWindow();
stage.close();
}
@FXML
void classMouseClicked(MouseEvent event) throws SQLException {
System.out.println("clicked");
}
private ObservableList<StudentMaster> data ;
private ObservableList<AvailableClasses>totalClasses;
public void setStudentData(ObservableList<StudentMaster> data)
{
this.data = data ;
}
@FXML
void doneBtnClicked(ActionEvent event)
{
String name = nameBox.getText();
Integer ref = 1;
String standard = "1";
String division = "A";
String admissionNo = admBox.getText();
String sex = "M";
String religion = religionBox.getText();
String caste = casteBox.getText();
String address = addressBox.getText();
String SQLquery = "INSERT INTO student (student_name," +
"fk_grp_ref,"+
"student_std," +
"student_div," +
"student_admn_no," +
"student_sex," +
"student_religion," +
"student_caste," +
"student_address) " +
"VALUES ('"+name+"','"+ref+"', '"+standard+"'," +
" '"+division+"', '"+admissionNo+"', '"+sex+"', " +
"'"+religion+"', '"+caste+"', '"+address+"')";
ExecuteSQL newQuery = new ExecuteSQL();
Integer executeStatus = newQuery.ExecuteSQL(SQLquery);
if (executeStatus != 0)
{
System.out.println("Data Inserted");
}
else
{
System.out.println("Error in execution");
}
StudentMaster student = new StudentMaster();
StudentMaster studentData = new StudentMaster();
studentData.name.set(name);
studentData.admNo.set(admissionNo);
studentData.stdDiv.set(division);
studentData.stdClass.set(standard);
studentData.studentId.set(executeStatus);
data.add(studentData);
// Close the Window after successfully inserted
Node node = (Node)event.getSource();
Stage stage = (Stage)node.getScene().getWindow();
stage.close();
}
@FXML
void resetBtnClicked(ActionEvent event) {
nameBox.setText("");
addressBox.setText("");
admBox.setText("");
dobBox.getEditor().clear();
religionBox.setText("");
casteBox.setText("");
}
@FXML
void initialize() throws SQLException {
assert nameBox != null : "fx:id=\"nameBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert classBox != null : "fx:id=\"classBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert divBox != null : "fx:id=\"divBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert admBox != null : "fx:id=\"admBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert religionBox != null : "fx:id=\"religionBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert casteBox != null : "fx:id=\"casteBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert addressBox != null : "fx:id=\"addressBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert dobBox != null : "fx:id=\"dobBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert sexBox != null : "fx:id=\"sexBox\" was not injected: check your FXML file 'newStudent.fxml'.";
assert resetBtn != null : "fx:id=\"resetBtn\" was not injected: check your FXML file 'newStudent.fxml'.";
assert cancelBtn != null : "fx:id=\"cancelBtn\" was not injected: check your FXML file 'newStudent.fxml'.";
assert doneBtn != null : "fx:id=\"doneBtn\" was not injected: check your FXML file 'newStudent.fxml'.";
String query = "select * from class";
ExecuteSQL newSelectClassesQuery = new ExecuteSQL();
ResultSet rs = newSelectClassesQuery.GetClassesList(query);
totalClasses = FXCollections.observableArrayList();
while(rs.next())
{
// AvailableClasses classesData = new AvailableClasses();
classBox.getItems().add(rs.getString("class_name"));
}
rs.close();
}
}
ExecuteSQL.java//执行我的 SQL 查询
package customlib;
import database.DatabaseAccess;
import java.sql.*;
public class ExecuteSQL {
private Connection connection;
public Integer ExecuteSQL(String query)
{
DatabaseAccess newConnection = new DatabaseAccess();
connection = newConnection.startConnection();
try
{
PreparedStatement preparedStatement = (PreparedStatement) connection.prepareStatement(query);
preparedStatement.executeUpdate();
ResultSet rs = connection.createStatement().executeQuery("select last_insert_id() as last_id from student");
int lastid = 0;
while(rs.next())
{
lastid = rs.getInt("last_id");
}
newConnection.shutdown();
return lastid;
}
catch (SQLException e)
{
e.printStackTrace();
newConnection.shutdown();
return 0;
}
}
public ResultSet GetClassesList(String query)
{
DatabaseAccess newConnection = new DatabaseAccess();
connection = newConnection.startConnection();
ResultSet rs;
try
{
rs = connection.createStatement().executeQuery(query);
newConnection.shutdown();
rs.close();
return rs;
}
catch (SQLException e)
{
e.printStackTrace();
newConnection.shutdown();
rs = null;
return rs;
}
}
}
编辑:添加 newStudent.fxml 文件
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dashboard.AdmissionController">
<children>
<Pane layoutX="67.0" layoutY="92.0">
<children>
<TextField fx:id="nameBox" layoutX="64.0" layoutY="1.0" />
<ChoiceBox fx:id="classBox" layoutX="299.0" onMouseClicked="#classMouseClicked" prefHeight="26.0" prefWidth="61.0" />
<ChoiceBox fx:id="divBox" layoutX="396.0" layoutY="1.0" prefHeight="26.0" prefWidth="61.0" />
<Label layoutY="6.0" prefHeight="16.0" prefWidth="49.0" text="Name" />
<Label layoutX="257.0" layoutY="6.0" prefHeight="16.0" prefWidth="38.0" text="Class" />
<Label layoutX="368.0" layoutY="5.0" prefHeight="16.0" prefWidth="38.0" text="Div" />
<TextField fx:id="admBox" layoutX="64.0" layoutY="52.0" />
<Label layoutX="2.0" layoutY="57.0" prefHeight="16.0" prefWidth="61.0" text="Adm.No" />
<TextField fx:id="religionBox" layoutX="64.0" layoutY="98.0" />
<Label layoutX="2.0" layoutY="103.0" prefHeight="16.0" prefWidth="61.0" text="Religion" />
<TextField fx:id="casteBox" layoutX="63.0" layoutY="145.0" />
<Label layoutX="1.0" layoutY="150.0" prefHeight="16.0" prefWidth="61.0" text="Caste" />
<Label layoutX="251.0" layoutY="58.0" prefHeight="16.0" prefWidth="61.0" text="Address" />
<TextArea fx:id="addressBox" layoutX="306.0" layoutY="50.0" prefHeight="116.0" prefWidth="267.0" />
<Label layoutX="1.0" layoutY="196.0" prefHeight="16.0" prefWidth="61.0" text="DOB" />
<DatePicker fx:id="dobBox" layoutX="61.0" layoutY="192.0" prefHeight="26.0" prefWidth="170.0" />
<ChoiceBox fx:id="sexBox" layoutX="500.0" layoutY="1.0" prefHeight="26.0" prefWidth="61.0" />
<Label layoutX="472.0" layoutY="5.0" prefHeight="16.0" prefWidth="38.0" text="Sex" />
<Button fx:id="resetBtn" layoutX="2.0" layoutY="272.0" mnemonicParsing="false" onAction="#resetBtnClicked" text="Reset" />
<Button fx:id="cancelBtn" layoutX="425.0" layoutY="271.0" mnemonicParsing="false" onAction="#cancelBtnClicked" text="Cancel" />
<Button fx:id="doneBtn" layoutX="512.0" layoutY="269.0" mnemonicParsing="false" onAction="#doneBtnClicked" prefHeight="26.0" prefWidth="62.0" text="Done" />
</children>
</Pane>
<Label layoutX="261.0" layoutY="40.0" prefHeight="25.0" prefWidth="170.0" text="NEW ADMISSION">
<font>
<Font size="20.0" />
</font>
</Label>
</children>
</Pane>
最佳答案
问题是,getClassesList
返回一个已经关闭的结果集:
try {
rs = connection.createStatement().executeQuery(query);
newConnection.shutdown(); // why shut down the connection when you plan to work on rs?
rs.close(); // same question applies here
return rs;
}
但是在您的 AdmissionController 中您想要使用 ResultSet:
ResultSet rs = newSelectClassesQuery.GetClassesList(query); // already closed!
totalClasses = FXCollections.observableArrayList();
while(rs.next()) // exception
{
// AvailableClasses classesData = new AvailableClasses();
classBox.getItems().add(rs.getString("class_name"));
}
rs.close();
提示:重构您的类 ;-)
如果你问我,你应该考虑创建 DAO,从数据库获取和返回你的类。那么您的 UI 代码就不需要了解 ResultSet 生命周期。
关于java - 运行 Javafx 应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37078262/
我不知道这是不是问这种问题的最佳地点, 我看到一些 JavaFX伙计们,重新标记 一些问题通过替换 javafx来自 javafx-2并采用新的 javafx-8 .它被弃用了还是什么? 编辑 : 不
错误本身: Error:java: invalid flag: --add-modules=javafx.fxml,javafx.graphics,javafx.controls,javafx.bas
这个想法是让一个应用程序在每个显示器上显示两个不同的窗口(阶段),该应用程序应该知道计算机有多少个显示器及其分辨率。 javafx有可能吗? 最佳答案 对于当前版本的 JavaFX (2.2),您可以
我正在将我的项目从 javafx 1.3 转换为 javafx 2.1。但我对 javafx.lang 有疑问包裹。 最佳答案 JavaFX 1.3 lang 包内容被拆分并移至下一个位置: 时长变为
当我尝试将标签添加到 gridpane 中时,如第二张图片所示,它不起作用。我已经尝试了很多东西,比如添加 CSS,但它仍然无法正常工作。为什么第 113 和 114 行不起作用? (opcje.se
我有一个JavaFX ContextMenu分配给滚动面板的鼠标右键单击。它会打开,但在滚动 Pane 外部单击时不会关闭。我可以在滚动 Pane 中添加另一个鼠标事件以将其隐藏,但这只能解决1个问题
我有一个tableview,其中附有一个可观察到的自定义类对象的列表(类类型:SalesInvoiceNetSale)。该表中的所有数据都可以正常显示。可观察列表中的最后一项是总计行(类类型:Sale
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 2年前关闭。 Improve this questi
我想知道如何在JavaFX中绘制半圆。我尝试使用Shape和QuadCurve,但无法制作出完美的半圆。 这是我要绘制的图片: 最佳答案 您链接的图片实际上是一个半圆环。您可以通过绘制嵌套的2条圆弧和
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我正在寻找 JavaFX 支持的图像类型(最新)列表,例如PNG、JPEG、TIFF。不同的搜索引擎没有帮助......知道从哪里开始吗? 更特别的是,我对 16 位灰度图像(不同格式)和罕见的受支持
我希望在 javafx 中让标签每 0.1 秒闪烁一次。文本显示在后台运行的 ImageView gif 的顶部。我将如何去做,或者您对最佳方法有什么建议? 谢谢 最佳答案 @fabian 的解决方案
我需要测试所选项目的值以调用不同的方法,因此我编写了添加侦听器的代码,但是该代码生成语法错误 @FXML private JFXComboBox cmbComp; cmbComp.valuePrope
我正在 Javafx 中编写一个非常简单的应用程序,其中舞台上有一个带有文本框的按钮作为一个场景。现在,我想要的行为是,当我单击按钮时,我可以使用另一个按钮加载另一个场景和舞台上的一个文本框,然后删除
编辑:如果用户单击“删除”以删除 ListView 中的项目,我会弹出一个警告框。它有效,但我希望它能超越原来的舞台。它出现在我的第一台显示器上。有什么方法可以设置警报显示时的位置吗? 请注意,“所有
我想使用 JavaFX 编写一个笔画绘图应用程序。我有一个压敏绘图板,如果能够读取笔的压力和倾斜值,那就太好了。 JavaFX 有一个 API 可以处理鼠标、触摸和滑动输入,但似乎没有任何东西可以产生
我在 JavaFX 中使用条形图和折线图。当我使两个图表大小相同并将它们放在同一位置时,它们完美地相互重叠。我如何使折线图显示在条形图的顶部。 目前我已将它们的不透明度设置为 0.7,这样它们“看起来
此问题与 this 相关。现在我想为字段值等于某个值的行着色。 @FXML private TableView tv_mm_view; @FXML private Ta
我有一个程序,可以生成高度图(0-255 的整数的 2D 数组),并使用 Shape3D“Box”对象为每个“像素”构建 3D View ,其高度与其在高度图中的值成比例。这会创建一个看起来很酷的四四
我想为 JavaFX 创建上下文菜单。这是我测试过的代码。但是由于某种原因,当我右键单击树节点时没有上下文菜单。你能帮我找出我的错误吗。 import java.util.Arrays; import
我是一名优秀的程序员,十分优秀!