JavaFX-填充表视图-PropertyValueFactory不是有效的类型

时间:2019-03-15 13:21:36

标签: java javafx tableview fxml

我遵循了该教程:https://docs.oracle.com/javafx/2/fxml_get_started/fxml_tutorial_intermediate.htm#CACFHDEJ

我的第一个TableView填充就好了。但是我在另一个阶段的第二个没有。 我收到错误:“ javafx.fxml.LoadException:PropertyValueFactory不是有效的类型。”每次。

myfxml类:

<?xml version="1.0" encoding="UTF-8"?>
<?import MainGui.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.collections.*?> 
<?import java.net.URL?>

<AnchorPane id="AnchorPane" fx:id="ap" prefHeight="537.0" prefWidth="736.0" 
xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="MainGui.DetailViewController">
   <children>
      <GridPane layoutY="6.0" prefHeight="526.0" prefWidth="736.0">
        <columnConstraints>
            <ColumnConstraints hgrow="SOMETIMES" maxWidth="143.0" 
minWidth="10.0" prefWidth="32.0" />
            <ColumnConstraints hgrow="SOMETIMES" maxWidth="263.0" 
minWidth="10.0" prefWidth="150.0" />
            <ColumnConstraints hgrow="SOMETIMES" maxWidth="186.0" 
minWidth="10.0" prefWidth="150.0" />
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" 
prefWidth="150.0" />
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" 
prefWidth="150.0" />
        </columnConstraints>
        <rowConstraints>
            <RowConstraints minHeight="10.0" prefHeight="30.0" 
vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" 
vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" 
vgrow="SOMETIMES" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
        <RowConstraints maxHeight="70.0" minHeight="10.0" prefHeight="41.0" vgrow="SOMETIMES" />
      <RowConstraints maxHeight="174.0" minHeight="10.0" prefHeight="161.0" vgrow="SOMETIMES" />
    </rowConstraints>
     <children>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Firmenname" textAlignment="CENTER" GridPane.columnIndex="1">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Kundengruppe" textAlignment="CENTER" GridPane.columnIndex="2">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Zielgruppe" textAlignment="CENTER" GridPane.columnIndex="3">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Telefon" textAlignment="CENTER" GridPane.columnIndex="1" GridPane.rowIndex="2">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Fax" textAlignment="CENTER" GridPane.columnIndex="2" GridPane.rowIndex="2">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Straße" textAlignment="CENTER" GridPane.columnIndex="3" GridPane.rowIndex="2">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Hausnummer" textAlignment="CENTER" GridPane.columnIndex="4" GridPane.rowIndex="2">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Postleitzahl" textAlignment="CENTER" GridPane.columnIndex="1" GridPane.rowIndex="4">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Ort" textAlignment="CENTER" GridPane.columnIndex="2" GridPane.rowIndex="4">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Website" textAlignment="CENTER" GridPane.columnIndex="3" GridPane.rowIndex="4">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="E-Mail" textAlignment="CENTER" GridPane.columnIndex="4" GridPane.rowIndex="4">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Label>
        <TextField fx:id="txtfdName" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdGroup" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="2" GridPane.rowIndex="1">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdSecGroup" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="3" GridPane.rowIndex="1">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdTel" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="1" GridPane.rowIndex="3">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdFax" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="2" GridPane.rowIndex="3">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdStreet" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="3" GridPane.rowIndex="3">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdNumber" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="4" GridPane.rowIndex="3">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdPlz" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="1" GridPane.rowIndex="5">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdCity" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="2" GridPane.rowIndex="5">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdWebsite" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="3" GridPane.rowIndex="5">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <TextField fx:id="txtfdMail" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="4" GridPane.rowIndex="5">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </TextField>
        <Button mnemonicParsing="false" prefHeight="41.0" prefWidth="174.0" text="Anlagen" GridPane.rowIndex="2">
           <GridPane.margin>
              <Insets left="5.0" right="2.0" />
           </GridPane.margin>
        </Button>
        <TableView fx:id="tblData" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.columnSpan="2147483647" GridPane.rowIndex="6">
          <columns>
            <TableColumn prefWidth="85.0" text="Vorname" >
              <cellValueFactory>
                 <PropertyValueFactory property="firstName" />
              </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="85.0" text="Nachname" >
              <cellValueFactory>
                 <PropertyValueFactory property="name" />
              </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="85.0" text="Funktion" >
                <cellValueFactory>
                 <PropertyValueFactory property="position" />
              </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="85.0" text="Druchwahl" >
              <cellValueFactory>
                 <PropertyValueFactory property="tel" />
              </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="85.0" text="Mobil" >
              <cellValueFactory>
                 <PropertyValueFactory property="mobil" />
              </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="85.0" text="E-Mail" >
              <cellValueFactory>
                 <PropertyValueFactory property="mail" />
              </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="85.0" text="Geburtstag" >
              <cellValueFactory>
                 <PropertyValueFactory property="bday" />
              </cellValueFactory>
            </TableColumn>
            <TableColumn prefWidth="85.0" text="Hobbys" >
              <cellValueFactory>
                 <PropertyValueFactory property="hobby" />
              </cellValueFactory>
            </TableColumn>
          </columns>
           <GridPane.margin>
              <Insets right="2.0" />
           </GridPane.margin>
        </TableView>
        <Label alignment="CENTER" contentDisplay="BOTTOM" prefHeight="52.0" prefWidth="188.0" text="Bundesland" textAlignment="CENTER" GridPane.columnIndex="4">
           <font>
              <Font name="Segoe UI Light" size="15.0" />
           </font>
        </Label>
        <TextField fx:id="txtfdBdl" onAction="#onActionChange" prefHeight="37.0" prefWidth="184.0" GridPane.columnIndex="4" GridPane.rowIndex="1" />
     </children>
  </GridPane>
   </children>
</AnchorPane>

在这里您可以看到我也导入了我的Package(MainGui。*),因此这里没有错误。

我的控制器类如下:

/*
 * To change this license header, choose License Headers in Project 
Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package MainGui;

import algorithm.ObjectValuePair;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.ResourceBundle;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
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.layout.AnchorPane;
import javafx.stage.Stage;
import org.json.simple.JSONObject;

/**
 * FXML Controller class
 *
 * @author 
 */
public class DetailViewController implements Initializable {

@FXML
private TextField txtfdName;
@FXML
private TextField txtfdGroup;
@FXML
private TextField txtfdSecGroup;
@FXML
private TextField txtfdTel;
@FXML
private TextField txtfdFax;
@FXML
private TextField txtfdStreet;
@FXML
private TextField txtfdNumber;
@FXML
private TextField txtfdPlz;
@FXML
private TextField txtfdCity;
@FXML
private TextField txtfdWebsite;
@FXML
private TextField txtfdMail;
@FXML
private TextField txtfdBdl;

private String title;
private DetailedCustomer dc;
@FXML
private AnchorPane ap;
@FXML
private TableView<PartnerOverview> tblData;

/**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {

}

@FXML
private void onActionChange(ActionEvent event) {
}

public void setDetailedCusotmerBasics(String id, JsonDatabaseConnector jdc){
    dc = new DetailedCustomer(id, jdc);
    this.txtfdBdl.setText(dc.getBdl());
    this.txtfdName.setText(dc.getName());
    this.txtfdGroup.setText(dc.getGroup());
    this.txtfdSecGroup.setText(dc.getSubGroup());
    this.txtfdTel.setText(dc.getTel());
    this.txtfdFax.setText(dc.getFax());
    this.txtfdStreet.setText(dc.getStreet());
    this.txtfdNumber.setText(dc.getHnr());
    this.txtfdPlz.setText(dc.getPlz());
    this.txtfdCity.setText(dc.getCity());
    this.txtfdWebsite.setText(dc.getSite());
    this.txtfdMail.setText(dc.getMail());
    /*ArrayList<JSONObject> search = dc.getPartner();

    if(search != null){
        int size = search.size();
        for(int i = 0; i < size; i++){
            ObservableList<PartnerOverview> data = tblData.getItems();
            data.add(new PartnerOverview(search.get(i)));
        }
    }*/
    ObservableList<PartnerOverview> data = tblData.getItems();
    data.add(new PartnerOverview("awd", "awd", "adw", "awd", "adw", "awd", "adw", "awd"));

}    



}

我的合作伙伴概述如下:

/*
 * To change this license header, choose License Headers in Project 
Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package MainGui;

import javafx.beans.property.SimpleStringProperty;
import org.json.simple.JSONObject;

 /**
 *
 * @author 
 */
public class PartnerOverview {
private SimpleStringProperty firstName = new SimpleStringProperty("");
private SimpleStringProperty name = new SimpleStringProperty("");
private SimpleStringProperty position = new SimpleStringProperty("");
private SimpleStringProperty tel = new SimpleStringProperty("");
private SimpleStringProperty mobil = new SimpleStringProperty("");
private SimpleStringProperty mail = new SimpleStringProperty("");
private SimpleStringProperty bday = new SimpleStringProperty("");
private SimpleStringProperty hobby = new SimpleStringProperty("");

public PartnerOverview(){
    this("","","","","","","","");
}

public PartnerOverview(String firstName, String name, String position, String tel, String mobil, String mail, String bday, String hobby){
    this.firstName.set(firstName);
    this.name.set(name);
    this.position.set(position);
    this.tel.set(tel);
    this.mobil.set(mobil);
    this.mail.set(mail);
    this.bday.set(bday);
    this.hobby.set(hobby);
}

public PartnerOverview(JSONObject obj){
    this.firstName.set((String) obj.get("Vorname")); 
    this.name.set((String) obj.get("Name")); 
    this.position.set((String) obj.get("Funktion"));
    JSONObject address = (JSONObject) obj.get("Adresse");
    this.tel.set((String) address.get("Durchwahl"));
    this.mobil.set((String) address.get("MobilTel"));
    this.mail.set((String) address.get("eMail"));
    this.bday.set((String) address.get("Geburtstag"));
    this.hobby.set((String) address.get("Hobbys"));
}

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

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

public String getName() {
    return name.get();
}

public void setName(String name) {
    this.name.set(name);
}

public String getPosition() {
    return position.get();
}

public void setPosition(String position) {
    this.position.set(position);
}

public String getTel() {
    return tel.get();
}

public void setTel(String tel) {
    this.tel.set(tel);
}

public String getMobil() {
    return mobil.get();
}

public void setMobil(String mobil) {
    this.mobil.set(mobil);
}

public String getMail() {
    return mail.get();
}

public void setMail(String mail) {
    this.mail.set(mail);
}

public String getBday() {
    return bday.get();
}

public void setBday(String bday) {
    this.bday.set(bday);
}

public String getHobby() {
    return hobby.get();
}

public void setHobby(String hobby) {
    this.hobby.set(hobby);
}



}

我看不到任何问题,并且以前在我的其他fxml类上都可以使用。有人可以帮忙吗?

0 个答案:

没有答案