我无法运行JavaFX应用程序。我只想将一些数据存储到表中并查看它。但我只是有错误,有人请帮助我。 这是我的控制器类
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable {
@FXML
TableView<Person> table;
@FXML
TableColumn<Person,Integer> number;
@FXML
TableColumn<Person,String> name;
@FXML
TableColumn<Person,String> surname;
@Override
public void initialize(URL location, ResourceBundle resources) {
table = new TableView<>();
number = new TableColumn<>();
name = new TableColumn<>();
surname = new TableColumn<>();
number.setCellValueFactory(new PropertyValueFactory<Person, Integer>("id"));
name.setCellValueFactory(new PropertyValueFactory<Person, String>("name"));
surname.setCellValueFactory(new PropertyValueFactory<Person, String>("surname"));
ObservableList<Person> data = FXCollections.observableArrayList(new Person(1,"fa","fafe"));
table.setItems(data);
table.getColumns().addAll(number,name,surname);
}
}
但我收到的错误是我从终端获得的错误,我将每个ID都提供给我的组件
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
at com.sun.javafx.application.LauncherImpl$$Lambda$1/1927950199.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: Error resolving onEditStart='#click', either the event handler is not in the Namespace or there is an error in the script.
/D:/work%20proyeqt%20immidetely/WorkWithTable/out/production/WorkWithTable/sample/sample.fxml:15
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2591)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:606)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:766)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2817)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2526)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3208)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091)
at sample.Main.start(Main.java:13)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/355529278.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
at com.sun.javafx.application.PlatformImpl$$Lambda$46/2000304245.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/225942701.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/2051067688.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda$38/517043427.run(Unknown Source)
... 1 more
这是错误只是在我的终端中发生。它可能是错的,请帮我解决这个问题。我只想将一些数据存储到我的表中,然后在应用程序中查看结果。
答案 0 :(得分:2)
欢迎来到Stack Overflow!
错误信息中的重要一行是:
Caused by: javafx.fxml.LoadException: Error resolving onEditStart='#click', either the event handler is not in the Namespace or there is an error in the script.
/D:/work%20proyeqt%20immidetely/WorkWithTable/out/production/WorkWithTable/sample/sample.fxml:15
这意味着sample.fxml第15行出现错误,特别是onEditStart='#click'
。它无法解析'onEditStart'或click()不是控制器中的函数。
答案 1 :(得分:0)
Caused by: javafx.fxml.LoadException: Error resolving onEditStart='#click', either the event handler is not in the Namespace or there is an error in the script.
/D:/work%20proyeqt%20immidetely/WorkWithTable/out/production/WorkWithTable/sample/sample.fxml:15
可能您的按钮上具有click方法,但您的控制器类中没有该方法