javaFx

时间:2019-02-06 09:49:54

标签: java javafx tableview

我尝试用Contacts填充TableView。我检查了typos(get and set),因为它已被java机器验证为实现列,但没有任何变化,我仍然具有相同的数据反射率错误

  

主类

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

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
    Parent root = 
    FXMLLoader.load(getClass().getResource("contactsScene.fxml"));
    primaryStage.setTitle("Contact World");
    primaryStage.setScene(new Scene(root, 700, 500));
    primaryStage.show();
}


public static void main(String[] args) {
    launch(args);
    }
}

  

联系方式

public class Contact {
    public SimpleStringProperty firstName;
    public SimpleStringProperty lastName;
    public SimpleStringProperty number;


    public Contact(String firstName, String lastName, String number) {
        this.firstName = new SimpleStringProperty(firstName);
        this.lastName = new SimpleStringProperty(lastName);
        this.number = new SimpleStringProperty(number);


    }

    public String getFirstName() {
        return firstName.get();
    }

    public SimpleStringProperty firstNameProperty() {return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName.set(firstName);
    }
 }
  

控制器类

 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.fxml.FXML;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableView;
 import javafx.scene.control.cell.PropertyValueFactory;

public class Controller{
     @FXML
    private TableView<Contact> contactTableView;
    ObservableList<Contact>data=FXCollections.observableArrayList();

    public void initialize(){
        data.addAll(new Contact("Joe","Factory","000000000"),
        new Contact("Mickael","Cell","000000000"),
        new Contact("Gerard","Data","00000000"),
        new Contact("john","Reflectivity","0000000000"));


        TableColumn firstNameCol=new TableColumn("First Name");
        firstnameCol.setCellValueFactory(new PropertyValueFactory<Contact, String>("firstName"));


        contactTableView.setItems(data);
        contactTableView.getColumns().addAll(firstNameCol);

    }

}}

  

FXML

     <?import javafx.scene.control.Menu?>
     <?import javafx.scene.control.MenuBar?>
     <?import javafx.scene.control.TableColumn?>
     <?import javafx.scene.control.TableView?>
     <?import javafx.scene.layout.BorderPane?>
     <?import javafx.scene.layout.VBox?>

     <?import javafx.scene.control.ListView?>
     <BorderPane xmlns:fx="http://javafx.com/fxml/1" 
     xmlns="http://javafx.com/javafx/8.0.172-ea" 
     fx:controller="contactManagement.Controller"><top><VBox>
     <MenuBar><Menu text="contacts" /> </MenuBar></VBox></top>
     <center>
     <TableView  fx:id="contactTableView">

     <columnResizePolicy>
     <TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
     </columnResizePolicy>

     </TableView></center>
     </BorderPane>

  

Stacktrace

févr。 2019年6月6日3:47:23 javafx.scene.control.cell.PropertyValueFactory getCellDataReflectively 警告:无法在具有提供的类类型的PropertyValueFactory中检索属性'firstName': javafx.scene.control.cell.PropertyValueFactory@69fe6c51:class contactManagement.ContactManager.Contact java.lang.RuntimeException:java.lang.IllegalAccessException:模块javafx.base无法访问类contactManagement.ContactManager.Contact(在Contact模块中),因为模块Contact不会将contactManagement.ContactManager打开到javafx.base     在javafx.base / com.sun.javafx.property.PropertyReference.getProperty(PropertyReference.java:199)     在javafx.controls / javafx.scene.control.cell.PropertyValueFactory.getCellDataReflectively(PropertyValueFactory.java:182)     在javafx.controls / javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:154)     在javafx.controls / javafx.scene.control.cell.PropertyValueFactory.call(PropertyValueFactory.java:133)     在javafx.controls / javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:593)     在javafx.controls / javafx.scene.control.TableColumn.getCellObservableValue(TableColumn.java:578)     在javafx.controls / javafx.scene.control.TableCell.updateItem(TableCell.java:646)     在javafx.controls / javafx.scene.control.TableCell.indexChanged(TableCell.java:469)     在javafx.controls / javafx.scene.control.IndexedCell.updateIndex(IndexedCell.java:120)     在javafx.controls / javafx.scene.control.skin.TableSkinUtils.resizeColumnToFitContent(TableSkinUtils.java:119)     在javafx.controls / javafx.scene.control.skin.TableSkinUtils.resizeColumnToFitContent(TableSkinUtils.java:86)     在javafx.controls / javafx.scene.control.skin.TableColumnHeader.doColumnAutoSize(TableColumnHeader.java:573)     在javafx.controls / javafx.scene.control.skin.TableColumnHeader.updateScene(TableColumnHeader.java:516)     在javafx.controls / javafx.scene.control.skin.TableColumnHeader.lambda $ new $ 0(TableColumnHeader.java:159)     在javafx.controls / com.sun.javafx.scene.control.LambdaMultiplePropertyChangeListenerHandler.lambda $ new $ 1(LambdaMultiplePropertyChangeListenerHandler.java:49)     在javafx.base / javafx.beans.value.WeakChangeListener.changed(WeakChangeListener.java:86)     在javafx.base / com.sun.javafx.binding.ExpressionHelper $ SingleChange.fireValueChangedEvent(ExpressionHelper.java:181)     在javafx.base / com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)     在javafx.base / javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)     在javafx.base / javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)     在javafx.graphics/javafx.scene.Node$ReadOnlyObjectWrapperManualFire.fireSuperValueChangedEvent(Node.java:1054)     在javafx.graphics/javafx.scene.Node.invalidatedScenes(Node.java:1114)     在javafx.graphics/javafx.scene.Node.setScenes(Node.java:1152)     在javafx.graphics/javafx.scene.Parent$2.onChanged(Parent.java:369)     在javafx.base / com.sun.javafx.collections.TrackableObservableList.lambda $ new $ 0(TrackableObservableList.java:45)     在javafx.base / com.sun.javafx.collections.ListListenerHelper $ Generic.fireValueChangedEvent(ListListenerHelper.java:329)     在javafx.base / com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)     在javafx.base / javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)     在javafx.base / javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)     在javafx.base / javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)     在javafx.base / javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)     在javafx.base / javafx.collections.ModifiableObservableListBase.setAll(ModifiableObservableListBase.java:90)     在javafx.base / com.sun.javafx.collections.VetoableListDecorator.setAll(VetoableListDecorator.java:116)     在javafx.controls / javafx.scene.control.skin.NestedTableColumnHeader.updateContent(NestedTableColumnHeader.java:578)     在javafx.controls / javafx.scene.control.skin.NestedTableColumnHeader.updateTableColumnHeaders(NestedTableColumnHeader.java:504)     在javafx.controls / javafx.scene.control.skin.NestedTableColumnHeader.checkState(NestedTableColumnHeader.java:638)     在javafx.controls / javafx.scene.control.skin.NestedTableColumnHeader.computePrefHeight(NestedTableColumnHeader.java:345)     在javafx.graphics/javafx.scene.Parent.prefHeight(Parent.java:1031)     在javafx.graphics/javafx.scene.layout.Region.prefHeight(Region.java:1559)     在javafx.controls / javafx.scene.control.skin.TableHeaderRow.computePrefHeight(TableHeaderRow.java:376)     在javafx.controls / javafx.scene.control.skin.TableHeaderRow.computeMinHeight(TableHeaderRow.java:369)     在javafx.graphics/javafx.scene.Parent.minHeight(Parent.java:1059)     在javafx.graphics/javafx.scene.layout.Region.minHeight(Region.java:1525)     在javafx.controls / javafx.scene.control.SkinBase.computeMinHeight(SkinBase.java:311)     在javafx.controls / javafx.scene.control.Control.computeMinHeight(Control.java:512)     在javafx.graphics/javafx.scene.Parent.minHeight(Parent.java:1059)     在javafx.graphics/javafx.scene.layout.Region.minHeight(Region.java:1525)     在javafx.graphics/javafx.scene.layout.Region.computeChildMinAreaHeight(Region.java:1915)     在javafx.graphics/javafx.scene.layout.BorderPane.getAreaHeight(BorderPane.java:630)     在javafx.graphics/javafx.scene.layout.BorderPane.computeMinHeight(BorderPane.java:427)     在javafx.graphics/javafx.scene.Parent.minHeight(Parent.java:1059)     在javafx.graphics/javafx.scene.layout.Region.minHeight(Region.java:1525)     在javafx.graphics/javafx.scene.layout.BorderPane.layoutChildren(BorderPane.java:497)     在javafx.graphics/javafx.scene.Parent.layout(Parent.java:1204)     在javafx.graphics/javafx.scene.Scene.doLayoutPass(Scene.java:576)     在javafx.graphics/javafx.scene.Scene.preferredSize(Scene.java:1748)     在javafx.graphics/javafx.scene.Scene$2.preferredSize(Scene.java:393)     在javafx.graphics/com.sun.javafx.scene.SceneHelper.preferredSize(SceneHelper.java:66)     在javafx.graphics/javafx.stage.Window$12.invalidated(Window.java:1086)     在javafx.base / javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)     在javafx.base / javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)     在javafx.graphics/javafx.stage.Window.setShowing(Window.java:1174)     在javafx.graphics/javafx.stage.Window.show(Window.java:1189)     在javafx.graphics/javafx.stage.Stage.show(Stage.java:273)     在Contact / contactManagement.Main.start(Main.java:16)     在javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)     在javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)     在javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)     在java.base / java.security.AccessController.doPrivileged(本机方法)     在javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)     在javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)     在javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(本机方法)     在javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)     在java.base / java.lang.Thread.run(Thread.java:834) 由以下原因引起:java.lang.IllegalAccessException:模块javafx.base无法访问类contactManagement.ContactManager.Contact(在Contact模块中),因为模块Contact并未打开javafx.base的contactManagement.ContactManager。     在javafx.base / com.sun.javafx.property.MethodHelper.invoke(MethodHelper.java:69)     在javafx.base / com.sun.javafx.property.PropertyReference.getProperty(PropertyReference.java:197)     ...还有73

此刻,我只是尝试尝试firstName。我认​​为我的导入很好。

0 个答案:

没有答案