Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Опять нужна помощь Javafx TableView / 7 сообщений из 7, страница 1 из 1
29.12.2016, 19:53
    #39377949
Опять нужна помощь Javafx TableView
Я новичок, не могу понять почему не работает, до этого делал 1 проект по тому-же принципу и все работало О_о.

Структура проекта
-Object
--Agreement

-controllers
--FXMLDocumentController

-interfaces
--AgreementInterfase
---interfaces.impls
--CollectionAgreement

-krbd
--FXMLDocument.fxml
--KrBd

проблема появляется когда пытаюсь заполнить таблицу через контроллер
Код: java
1.
        TableWieView.setItems(agreementList.getAgreementList()); 



а вот когда заполняю через FXML то все работает
Код: xml
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>


вот какую ошибку оно мне выдает когда заполняю через контроллер
Код: java
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



Код: java
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();
    }
    
    

}



Код: java
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());      
    }    
   
}


Код: java
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;
        
    }
}


Код: java
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);
    }
    
}



Код: xml
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>


Заранее благодарю!
...
Рейтинг: 0 / 0
30.12.2016, 00:17
    #39378041
Kripke
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Опять нужна помощь Javafx TableView
ВладимирOdessA,
проблема в пути к ресурсу, должно быть так
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
public class KrBd extends Application {
    
    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("/controllers/FXMLDocument.fxml"));
        //...
    }     
}


у вас Application лежит в пакете krbd, а fxml в controllers (ну судя по классу FXMLDocumentController)
...
Рейтинг: 0 / 0
30.12.2016, 00:21
    #39378042
Kripke
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Опять нужна помощь Javafx TableView
Прочитал внимательней структуру проекта, в общем верните FXMLDocument.fxml назад в controllers, и укажите правильный путь к ресурсу
ВладимирOdessAСтруктура проекта
-Object
--Agreement

-controllers
--FXMLDocumentController

-interfaces
--AgreementInterfase
---interfaces.impls
--CollectionAgreement

-krbd
--FXMLDocument.fxml
--KrBd

И не называйте пакеты с большой буквы :)
...
Рейтинг: 0 / 0
30.12.2016, 09:46
    #39378149
Опять нужна помощь Javafx TableView
Kripke, с классами я обязательно исправлюсь!

Ех не помогло все равно ругается((
Код: java
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.
Exception in Application start method
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/run1766345908/KrBd.jar!/controllers/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
Deleting directory C:\Users\User\Documents\NetBeansProjects\KrBd\dist\run1766345908
jfxsa-run:
СБОРКА УСПЕШНО ЗАВЕРШЕНА (общее время: 13 секунды)
...
Рейтинг: 0 / 0
30.12.2016, 11:50
    #39378215
Petro123
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Опять нужна помощь Javafx TableView
ВладимирOdessA,
у меня так работает:
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
XXXXController.java
==========================
  ....
  private ObservableList<Record> recordData = FXCollections.observableArrayList();
	.....
	@FXML
	private TableView<Record> personTable;
.....
personTable.setItems(recordData);
...
Рейтинг: 0 / 0
03.01.2017, 15:30
    #39379186
Опять нужна помощь Javafx TableView
Petro123,

Все равно не работает я сделал код по новой и... все работает О_о не понятно что было О_О
...
Рейтинг: 0 / 0
03.01.2017, 15:30
    #39379187
Опять нужна помощь Javafx TableView
Всех с Новым Годом!
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Опять нужна помощь Javafx TableView / 7 сообщений из 7, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]