我用java8,JAVAFX,spring,hibernate,jpa,mysql编写程序 . 我要将程序的服务器部分与javafx连接起来 .

当我点击带有main→run作为java aplication运行的类时,会出现以下问题:

log4j:WARN No appenders could be found for logger (org.jboss.resteasy.plugins.providers.DocumentProvider).
log4j:WARN Please initialize the log4j system properly.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Sylwia/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Sylwia/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Sylwia/.m2/repository/org/slf4j/slf4j-simple/1.5.8/slf4j-simple-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Unknown Source)
    at com.sun.javafx.application.LauncherImpl$$Lambda$48/1732398722.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException: 
/C:/Users/Sylwia/git/Praca%20inzynierska%203/Praca%20inzynierska%202/target/classes/fxml/productComponent.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at pl.ftims.praca.restClientJavafx.RestClient.start(RestClient.java:17)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Unknown Source)
    at com.sun.javafx.application.LauncherImpl$$Lambda$51/1441419654.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$45/1051754451.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$164(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$47/742445343.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(Unknown Source)
    at com.sun.javafx.application.PlatformImpl$$Lambda$46/1775282465.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$141(Unknown Source)
    at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source)
    ... 1 more
Caused by: java.lang.NullPointerException
    at pl.ftims.praca.restClientJavafx.FXMLController.initialize(FXMLController.java:140)
    ... 23 more
Exception running application pl.ftims.praca.restClientJavafx.RestClient
//////////////////////////////////////////////////////////////////////

我应该首先关注问题:

at pl.ftims.praca.restClientJavafx.RestClient.start(RestClient.java:17)

要么:

Caused by: java.lang.NullPointerException
    at pl.ftims.praca.restClientJavafx.FXMLController.initialize(FXMLController.java:140)
    ... 23 more

我的RestClient类:

package pl.ftims.praca.restClientJavafx;


import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class RestClient extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        //When using the Class.getResource method, 
        //you must provide a local path from the location of the class on which is called the method.
        //Parent root = FXMLLoader.load(RestClient.class.getResource("/fxml/components.fxml"));
        Parent root = FXMLLoader.load(RestClient.class.getResource("/fxml/productComponent.fxml"));
        //I also had to use Parent root = FXMLLoader.load(getClass().getResource("/fxml/Scene.fxml"));

        /*FXMLLoader loader = new FXMLLoadergetClass().getResource("main.fxml");
loader.setController(new MainController(path));
Pane mainPane = loader.load();*/        
        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.show();
    }

    /**
     * The main() method is ignored in correctly deployed JavaFX application.
     * main() serves only as fallback in case the application can not be
     * launched through deployment artifacts, e.g., in IDEs with limited FX
     * support. NetBeans ignores main().
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}

FXMLController类

package pl.ftims.praca.restClientJavafx;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.cell.TextFieldTableCell;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import pl.ftims.praca.model.ProductWrapper;
import pl.ftims.praca.model.Products;

public class FXMLController implements Initializable {

    @FXML
    private TableView productTable;
    @FXML
    private TableColumn idColumn;
    @FXML
    private TableColumn nameColumn;
    @FXML
    private TableColumn sellingPriceColumn;
    @FXML
    private TableColumn purchasePriceColumn;

    @FXML
    private TextField idField;//tego nie bylo chyba, bo nie mozna przeciez zmieniac id
    @FXML
    private TextField nameField;
    @FXML
    private TextField sellingPriceField;
    @FXML
    private TextField purchasePriceField;
/*private Long id;
    private String name;
    private Double sellingPrice;
    private Double purchasePrice; //cena zakupu
    @ManyToOne
    private Storages storage; */

    private List<Products> listOfProducts = null;
    private List<Fxproduct> listOfFxProducts = null;
    private ObservableList<Fxproduct> listOfObservableList = null;
    private final static String REST_ROOT_URL = "http://localhost:8080/rest/";
    private final Client client = ClientBuilder.newClient();

    @FXML
    private void remove(ActionEvent event) { //ok rozumiem

        Fxproduct fxproduct = (Fxproduct) productTable.getSelectionModel().getSelectedItem();
        listOfObservableList.remove(fxproduct);

        Response response = client.target(REST_ROOT_URL).
//                path("publisher").
                path("products").
                path("deleteProductWithId").
                path(String.valueOf(fxproduct.getId())).
                request().delete();
    }

    @FXML
    private void save(ActionEvent event) {
        Products product = new Products();
        product.setName(nameField.getText());
        product.setPurchasePrice(Double.parseDouble(purchasePriceField.getText()));
        product.setSellingPrice(Double.parseDouble(sellingPriceField.getText()));

        Entity<Products> kitapEntity = Entity.entity(product, MediaType.APPLICATION_XML);
        Response response = client.target(REST_ROOT_URL).
                path("product").
                path("createProductWithData").
                request().
                post(kitapEntity);

        list(null);
        nameField.setText("");
        purchasePriceField.setText("");
        sellingPriceField.setText("");
    }

    @FXML
    private void list(ActionEvent event) { //NIE WIEM JAK TO ZROBIC

        Response response = client.target("http://localhost:8080/rest/").
                path("products").
                path("products").
                request(MediaType.APPLICATION_XML).
                get();
        ProductWrapper productWrapper = response.readEntity(ProductWrapper.class); //nie mam tego



        listOfProducts = (productWrapper.getProductList()==null)?new ArrayList<Products>(): productWrapper.getProductList();

//        listOfFxProducts = new ArrayList<>();
//        listOfFxProducts = new ArrayList<>(); //tak bylo, ale to jest java 1.7 i  sie nie kompilowalo


        for (Products k : listOfProducts) {
            listOfFxProducts.add(new Fxproduct(k));
        }

        listOfObservableList = FXCollections.observableList(listOfFxProducts);
        System.out.println(listOfObservableList);
        productTable.setItems(listOfObservableList);
        System.out.println(productTable);

    }

    public void kitapDuzenle(Products product) {

        Entity<Products> kitapEntity = Entity.entity(product, MediaType.APPLICATION_XML);
        Response response = client.target(REST_ROOT_URL).
                path("product").
                path("saveProduct2").
                request().
                put(kitapEntity);

    }

//    @SuppressWarnings("restriction")
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        productTable.setEditable(true); //tu jest blad, nullpointer

        //NAME
        nameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
        nameColumn.setOnEditCommit(
                new EventHandler<TableColumn.CellEditEvent<Fxproduct, String>>() {
                    @Override
                    public void handle(TableColumn.CellEditEvent<Fxproduct, String> t) {
                        ObservableList<Fxproduct> kitapListesi = t.getTableView().getItems();
                        Fxproduct kitap = kitapListesi.get(t.getTablePosition().getRow());
                        kitap.setName(t.getNewValue());
                        kitapDuzenle(kitap.getproduct());
                    }
                }
                );

        //SELLINGPRICE
        sellingPriceColumn.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleToStringConverter()));//tu jest blad
        sellingPriceColumn.setOnEditCommit(
                new EventHandler<TableColumn.CellEditEvent<Fxproduct, Double>>() {
                    @Override
                    public void handle(TableColumn.CellEditEvent<Fxproduct, Double> t) {
                        ObservableList<Fxproduct> kitapListesi = t.getTableView().getItems();
                        Fxproduct kitap = kitapListesi.get(t.getTablePosition().getRow());
                        kitap.setSellingPrice(t.getNewValue()); //tu ejst problem z double i siple double
                        kitapDuzenle(kitap.getproduct());
                    }
                }
                );

        //PURCHASEPRICE
        purchasePriceColumn.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleToStringConverter()));
        purchasePriceColumn.setOnEditCommit(
                new EventHandler<TableColumn.CellEditEvent<Fxproduct, Double>>() {
                    @Override
                    public void handle(TableColumn.CellEditEvent<Fxproduct, Double> t) {
                        ObservableList<Fxproduct> kitapListesi = t.getTableView().getItems();
                        Fxproduct kitap = kitapListesi.get(t.getTablePosition().getRow());
                        kitap.setPurchasePrice(t.getNewValue());//tu ejst problem z double i siple double
                        kitapDuzenle(kitap.getproduct());
                    }
                }
                );

        idColumn.setCellValueFactory(
                new PropertyValueFactory<Fxproduct, Long>("id"));
        nameColumn.setCellValueFactory(
                new PropertyValueFactory<Fxproduct, String>("name"));
        purchasePriceColumn.setCellValueFactory(
                new PropertyValueFactory<Fxproduct, Double>("price"));
        sellingPriceColumn.setCellValueFactory(
                new PropertyValueFactory<Fxproduct, Double>("price"));

        list(null);

    }
}

我认为问题是路径:Parent root = FXMLLoader.load(RestClient.class.getResource(“/ fxml / productComponent.fxml”));但我读到了这个:

How to reference javafx fxml files in resource folder?

JavaFX "Location is required." even though it is in the same package

Referencing class resource in FXML

Error loading fxml files from a folder other than the bin folder

JavaFX load resource from other package NetBeans

How to reference javafx fxml files in resource folder?

http://stackexchange.com/search?q=How+to+reference+javafx+fxml+files+in+resource+folder%3F

JavaFX - Exception in Application start method?我没找到答案 . /////////////////////////////编辑///////////////////

line 17 in RestClient: 
Parent root = FXMLLoader.load(RestClient.class.getResource("/fxml/productComponent.fxml")); 


line 139, 140 in FXMLController: 
public void initialize(URL url, ResourceBundle rb) { productTable.setEditable(true); // nullpointer