在我的应用程序中,我有一个表格视图。当用户双击某行时,有关该行的某些详细信息应显示在单独的详细信息窗口中。不知何故,它不起作用。我尝试了此站点的一些建议,但对我没有任何帮助。
我得到的错误:
javafx.fxml.LoadException:
/C:/Users/XXXXXXX/IdeaProjects/Projectfolder/out/production/Projectname/View/ReportPositions.fxml:6
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:928)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2711)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2531)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2413)
at Controller.MainWindow_Controller.openReport(MainWindow_Controller.java:373)
at Controller.MainWindow_Controller$1$1.handle(MainWindow_Controller.java:281)
at Controller.MainWindow_Controller$1$1.handle(MainWindow_Controller.java:277)
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.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$ClickGenerator.postProcess(Scene.java:3471)
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3399)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3767)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3486)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2495)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350)
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$350(GlassViewEventHandler.java:385)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$288/22489656.get(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:927)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/19633550.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InstantiationException: Controller.ReportPositions_Controller
at java.lang.Class.newInstance(Class.java:427)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
... 48 more
Caused by: java.lang.NoSuchMethodException: Controller.ReportPositions_Controller.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.newInstance(Class.java:412)
... 50 more
这是我的双击侦听器:
tvReports.setRowFactory(new Callback<TableView<Report>, TableRow<Report>>() {
@Override
public TableRow<Report> call(TableView<Report> tv) {
TableRow row = new TableRow();
row.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
try {
openReport();
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
return row;
}
});
openReport方法:
void openReport() throws IOException {
Report report = tvReports.getSelectionModel().getSelectedItem();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/View/ReportPositions.fxml"));
ReportPositions_Controller controller = fxmlLoader.getController();
controller.setPathDB(pathDB);
controller.setReport(report);
Parent root =(Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.initModality(Modality.WINDOW_MODAL);
stage.initStyle(StageStyle.UNDECORATED);
stage.setTitle("Reportpositions");
stage.setScene(new Scene(root));
stage.show();
}
“我的详细信息控制器”窗口
public class ReportPositions_Controller {
@FXML
private TableView tvReportPositions;
ObservableList<ObservableList> data;
private Report report;
private String pathDB;
public ReportPositions_Controller(Report report, String pathDB){
this.report = report;
this.pathDB = pathDB;
}
public void initialize() throws SQLException {
buildData(); //method that gets the the data which should be displayed afterwards
}
}
ReportPositions.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TableView?>
<TableView fx:id="tvReportPositions" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller.ReportPositions_Controller" />
我想将报告传递给控制器以获取报告的详细信息。
谢谢您的帮助