Я новичок, не могу понять почему не работает, до этого делал 1 проект по тому-же принципу и все работало О_о.
Структура проекта
-Object
--Agreement
-controllers
--FXMLDocumentController
-interfaces
--AgreementInterfase
---interfaces.impls
--CollectionAgreement
-krbd
--FXMLDocument.fxml
--KrBd
проблема появляется когда пытаюсь заполнить таблицу через контроллер
1.
TableWieView.setItems(agreementList.getAgreementList());
а вот когда заполняю через FXML то все работает
1.
2.
3.
4.
5.
6.
7.
8.
<items>
<FXCollections fx:factory="observableArrayList">
<Agreement adress="000" agreementName="205481" />
<Agreement adress="000" agreementName="205481" />
<Agreement adress="000" agreementName="205481" />
</FXCollections>
</items>
вот какую ошибку оно мне выдает когда заполняю через контроллер
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
Executing C:\Users\User\Documents\NetBeansProjects\KrBd\dist\run1723442824\KrBd.jar using platform C:\Program Files\Java\jdk1.8.0_111\jre/bin/java
Exception in Application start method
1+)fio= 000dieler=205481
2+)fio= 000dieler=305241
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:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
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:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
file:/C:/Users/User/Documents/NetBeansProjects/KrBd/dist/run1723442824/KrBd.jar!/krbd/FXMLDocument.fxml
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
at krbd.KrBd.start(KrBd.java:26)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
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$148(WinApplication.java:191)
... 1 more
Caused by: java.lang.NullPointerException
at controllers.FXMLDocumentController.initialize(FXMLDocumentController.java:36)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
... 17 more
Exception running application krbd.KrBd
Java Result: 1
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
package Object;
import javafx.beans.property.SimpleStringProperty;
public class Agreement {
private final SimpleStringProperty agreementName= new SimpleStringProperty("");
private final SimpleStringProperty Adress= new SimpleStringProperty("");
public Agreement() {
this("", "");
}
public Agreement(String namb, String fName) {
setAgreementName(namb);
setAdress(fName);
}
public void setAdress(String fName){
Adress.set(fName);
}
public void setAgreementName(String fName){
agreementName.set(fName);
}
public String getAdress() {
return Adress.get();
}
public String getAgreementName() {
return agreementName.get();
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
package controllers;
import Object.Agreement;
import interfaces.impls.CollectionAgreement;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
public class FXMLDocumentController implements Initializable {
@FXML private TableView<Agreement> TableWieView;
@FXML private TableColumn number_Agreement;
@FXML private TableColumn agreementName;
CollectionAgreement agreementList = new CollectionAgreement();
@Override
public void initialize(URL url, ResourceBundle rb) {
agreementList.test();
agreementList.testPrint();
TableWieView.setItems(agreementList.getAgreementList());
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
package interfaces.impls;
import Object.Agreement;
import interfaces.AgreementInterfase;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class CollectionAgreement implements AgreementInterfase{
private ObservableList<Agreement> agreementList = FXCollections.observableArrayList();
public void test(){
agreementList.add(new Agreement("000", "205481"));
agreementList.add(new Agreement("000", "305241"));
}
//печать теста
public void testPrint(){
int number =0;
System.out.println();
for(Agreement agreement: agreementList){
number++;
System.out.println(number+"+)fio= " + agreement.getAgreementName()+ "dieler="+agreement.getAdress());
}
}
@Override
public void add(Agreement agreement) {
agreementList.add(agreement);
}
@Override
public void update(Agreement agreement) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void delite(Agreement agreement) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public ObservableList<Agreement> getAgreementList(){
return agreementList;
}
public void setAgreementList(ObservableList<Agreement> agtementList){
this.agreementList= agtementList;
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
package krbd;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class KrBd extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
// CollectionAgreement tes = new CollectionAgreement();
// tes.test();
}
public static void main(String[] args) {
launch(args);
}
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.collections.*?>
<?import javafx.geometry.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<?import Object.*?>
<?import controllers.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controllers.FXMLDocumentController">
<children>
<AnchorPane layoutY="95.0" prefHeight="291.0" prefWidth="493.0">
<children>
<TableView layoutX="7.0" prefHeight="200.0" prefWidth="200.0" fx:id="TableWieW">
<columns>
<TableColumn prefWidth="75.0" text="C1" fx:id="number_Agreement">
<cellValueFactory>
<PropertyValueFactory property="agreementName" />
</cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="C2" fx:id="adress" >
<cellValueFactory>
<PropertyValueFactory property="adress" />
</cellValueFactory>
</TableColumn>
</columns>
<items>
<FXCollections fx:factory="observableArrayList">
<Agreement adress="000" agreementName="205481" />
<Agreement adress="000" agreementName="205481" />
<Agreement adress="000" agreementName="205481" />
</FXCollections>
</items>
</TableView>
</children>
</AnchorPane>
</children>
</AnchorPane>
Заранее благодарю!