简体   繁体   English

无法运行JavaFX应用程序

[英]Can't run JavaFX application

I can't run JavaFX application. 我无法运行JavaFX应用程序。 I just want to store some data into table and see it.But only I got mistake someone please help me. 我只想将一些数据存储到表中并查看它。但是只有我弄错了,请有人帮助我。 this is my controller class 这是我的控制器课

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);



    }
}

but I'm getting following errors which I get from terminal I gave every id to my components 但是我遇到了以下错误,这些错误是我从终端获得的,每个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

this is error just keeping occur in my terminal.what it might be wrong please help me to solve this. 这是错误,只是不断出现在我的终端中。可能是什么错误,请帮助我解决此问题。 I just want to store some data into my table that's it and see the result in application. 我只想将一些数据存储在表中,然后在应用程序中查看结果。

welcome to Stack Overflow! 欢迎使用Stack Overflow!

The important line in your error message is this one: 错误消息中的重要一行是这一行:

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

This means that there is an error on line 15 of sample.fxml, specifically where it says onEditStart='#click' . 这意味着sample.fxml的第15行出现错误,特别是在上面说onEditStart='#click' Either it can't resolve 'onEditStart' or click() isn't a function in the controller. 它无法解析'onEditStart'或click()不是控制器中的函数。

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

Probably you have click method on your button but you don't have it in your controller class 可能您的按钮上具有click方法,但在控制器类中没有该方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM