Ich habe seit geraumer Zeit ein Problem mit meinem Code. Und zwar möchte ich vorher eingegebene Daten in eine Tabelle übertragen.
Allerdings gibt mir INTELLIJ folgende Fehlermeldung wenn ich mir die Tabelle anzeigen lassen möchte:
"WARNUNG: Can not retrieve property 'uhr' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@6a84599c with provided class type: class java.lang.String
java.lang.IllegalStateException: Cannot read from unreadable property uhr"
Meine Controller-Klasse sieht so aus:
[CODE lang="java" title="Controller" highlight=""90-93""]package sample;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.*;
public class ControllerH implements Initializable{
medList medList = new medList();
@FXML
private Label aktuellerTag;
@FXML
public TableView<medList> plan = new TableView<medList>();
@FXML
private Button anzeigen;
@FXML
private Button loeschen;
@FXML
private TextField inputmed;
@FXML
protected ChoiceBox<String> choiceday;
@FXML
protected ChoiceBox<String> choicetime;
@FXML
private TextField inputpieces;
@FXML
protected ChoiceBox<String> choicehowpieces;
@FXML
protected ChoiceBox<String> choicetaking;
@FXML
private Button laufzeit;
@FXML
private DatePicker enddatum;
@FXML
private Button speichern;
@FXML
public void handleSpeichern(ActionEvent event) {
System.out.println("speichern");
medList.setMed(inputmed.getText());
medList.setEinnahme(choicetaking.getValue());
medList.setMenge(inputpieces.getText());
medList.setUhr(choicetime.getValue());
String Zeit = enddatum.getChronology().toString();
System.out.println(medList.getMed() + " "+ medList.getMenge()+ " "+medList.getEinnahme()+ " "+medList.getUhr());
}
private ObservableList getAusgabe(){
ObservableList ausgabe = FXCollections.observableArrayList();
ausgabe.setAll(medList.getMed(), medList.getMenge(), medList.getEinnahme(), medList.getUhr());
return ausgabe;
}
@FXML
private void handleAnzeigen(ActionEvent event){
System.out.println(medList.getMed() + " " + medList.getMenge()+" "+medList.getEinnahme()+" "+medList.getUhr());
ObservableList ausgabe = getAusgabe();
plan.setItems(ausgabe);
//Spalten erstellen
TableColumn<medList, String> spalteMedikament = new TableColumn<>("Medikament");
TableColumn<medList, String> spalteAnzahl = new TableColumn<>("Anzahl");
TableColumn<medList,String> spalteEinnahme = new TableColumn<>("Einnahme");
TableColumn<medList,String> spalteUhrzeit = new TableColumn<>("Uhrzeit");
//Spalten füllen
spalteMedikament.setCellValueFactory(new PropertyValueFactory<medList, String>("med"));
spalteAnzahl.setCellValueFactory(new PropertyValueFactory<medList, String>("menge"));
spalteEinnahme.setCellValueFactory(new PropertyValueFactory<medList, String>("einnahme"));
spalteUhrzeit.setCellValueFactory(new PropertyValueFactory<medList, String>("uhr"));
plan.getColumns().setAll(spalteMedikament, spalteAnzahl, spalteEinnahme, spalteUhrzeit);
}
@FXML
private void handleLoeschen(ActionEvent event)
{
medList selected = plan.getSelectionModel().getSelectedItem();
plan.getItems().remove(selected);
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
{
//choice boxen füllen
choiceday.getItems().addAll("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag");
choicetime.getItems().addAll("00:00", "00:15", "00:30", "00:45", "01:00", "01:15", "01:30", "01:45", "02:00","02:15","02:30","02:45","03:00","03:15","03:30","03:45","04:00","04:15","04:30","04:45","05:00","05:15","05:30","05:45", "06:00", "06:15", "06:30", "06:45","07:00", "07:15", "07:30", "07:45","08:00", "08:15", "08:30", "08:45","09:00", "09:15", "09:30", "09:45","10:00", "10:15", "10:30", "10:45","11:00", "11:15", "11:30", "11:45","12:00", "12:15", "12:30", "12:45","13:00", "13:15", "13:30", "13:45","14:00", "14:15", "14:30", "14:45","15:00", "15:15", "15:30", "15:45","16:00", "16:15", "16:30", "16:45","17:00", "17:15", "17:30", "17:45","18:00", "18:15", "18:30", "18:45","19:00", "19:15", "19:30", "19:45","20:00", "20:15", "20:30", "20:45","21:00", "21:15", "21:30", "21:45","22:00", "22:15", "22:30", "22:45","23:00", "23:15", "23:30", "23:45");
choicehowpieces.getItems().addAll("Ampullen", "Esslöffel", "Gramm", "Injektion", "Kapsel", "Milligramm", "Milliliter", "Packung", "Tabletten", "Teelöffel", "Tropfen", "Zäpfchen");
choicetaking.getItems().addAll("Auflösen", "Fette", "Flüssigkeit", "Trocken");
}
}[/CODE]
Die Einträge für die Tabelle läuft über meine Model-Klasse medList:
[CODE lang="java" title="medList (Model)"]package sample;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class medList {
public StringProperty med;
public void setMed(String value){ medProperty().set(value); }
public String getMed(){ return medProperty().get(); }
public StringProperty medProperty(){
if (med == null) med = new SimpleStringProperty(this, "medizinEingabe");
return med;
}
public StringProperty menge;
public void setMenge(String value){ mengeProperty().set(value); }
public String getMenge(){ return mengeProperty().get(); }
public StringProperty mengeProperty(){
if (menge == null) menge = new SimpleStringProperty(this, "mengenEingabe");
return menge;
}
public StringProperty einnahme;
public void setEinnahme(String value){ einnahmeProperty().set(value); }
public String getEinnahme(){ return einnahmeProperty().get(); }
public StringProperty einnahmeProperty(){
if (einnahme == null) einnahme = new SimpleStringProperty(this, "einnahmenEingabe");
return einnahme;
}
public StringProperty uhr;
public void setUhr(String value){ uhrProperty().set(value); }
public String getUhr(){ return uhrProperty().get(); }
public StringProperty uhrProperty(){
if (uhr == null) uhr = new SimpleStringProperty(this, "uhrZeit");
return uhr;
}
}
[/CODE]
Ich habe mir schon verschiedene ähnliche Probleme angesehen, aber keine der Lösungen traf auf mein Programm zu.
Allerdings gibt mir INTELLIJ folgende Fehlermeldung wenn ich mir die Tabelle anzeigen lassen möchte:
"WARNUNG: Can not retrieve property 'uhr' in PropertyValueFactory: javafx.scene.control.cell.PropertyValueFactory@6a84599c with provided class type: class java.lang.String
java.lang.IllegalStateException: Cannot read from unreadable property uhr"
Meine Controller-Klasse sieht so aus:
[CODE lang="java" title="Controller" highlight=""90-93""]package sample;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.*;
public class ControllerH implements Initializable{
medList medList = new medList();
@FXML
private Label aktuellerTag;
@FXML
public TableView<medList> plan = new TableView<medList>();
@FXML
private Button anzeigen;
@FXML
private Button loeschen;
@FXML
private TextField inputmed;
@FXML
protected ChoiceBox<String> choiceday;
@FXML
protected ChoiceBox<String> choicetime;
@FXML
private TextField inputpieces;
@FXML
protected ChoiceBox<String> choicehowpieces;
@FXML
protected ChoiceBox<String> choicetaking;
@FXML
private Button laufzeit;
@FXML
private DatePicker enddatum;
@FXML
private Button speichern;
@FXML
public void handleSpeichern(ActionEvent event) {
System.out.println("speichern");
medList.setMed(inputmed.getText());
medList.setEinnahme(choicetaking.getValue());
medList.setMenge(inputpieces.getText());
medList.setUhr(choicetime.getValue());
String Zeit = enddatum.getChronology().toString();
System.out.println(medList.getMed() + " "+ medList.getMenge()+ " "+medList.getEinnahme()+ " "+medList.getUhr());
}
private ObservableList getAusgabe(){
ObservableList ausgabe = FXCollections.observableArrayList();
ausgabe.setAll(medList.getMed(), medList.getMenge(), medList.getEinnahme(), medList.getUhr());
return ausgabe;
}
@FXML
private void handleAnzeigen(ActionEvent event){
System.out.println(medList.getMed() + " " + medList.getMenge()+" "+medList.getEinnahme()+" "+medList.getUhr());
ObservableList ausgabe = getAusgabe();
plan.setItems(ausgabe);
//Spalten erstellen
TableColumn<medList, String> spalteMedikament = new TableColumn<>("Medikament");
TableColumn<medList, String> spalteAnzahl = new TableColumn<>("Anzahl");
TableColumn<medList,String> spalteEinnahme = new TableColumn<>("Einnahme");
TableColumn<medList,String> spalteUhrzeit = new TableColumn<>("Uhrzeit");
//Spalten füllen
spalteMedikament.setCellValueFactory(new PropertyValueFactory<medList, String>("med"));
spalteAnzahl.setCellValueFactory(new PropertyValueFactory<medList, String>("menge"));
spalteEinnahme.setCellValueFactory(new PropertyValueFactory<medList, String>("einnahme"));
spalteUhrzeit.setCellValueFactory(new PropertyValueFactory<medList, String>("uhr"));
plan.getColumns().setAll(spalteMedikament, spalteAnzahl, spalteEinnahme, spalteUhrzeit);
}
@FXML
private void handleLoeschen(ActionEvent event)
{
medList selected = plan.getSelectionModel().getSelectedItem();
plan.getItems().remove(selected);
}
@Override
public void initialize(URL url, ResourceBundle resourceBundle)
{
//choice boxen füllen
choiceday.getItems().addAll("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag");
choicetime.getItems().addAll("00:00", "00:15", "00:30", "00:45", "01:00", "01:15", "01:30", "01:45", "02:00","02:15","02:30","02:45","03:00","03:15","03:30","03:45","04:00","04:15","04:30","04:45","05:00","05:15","05:30","05:45", "06:00", "06:15", "06:30", "06:45","07:00", "07:15", "07:30", "07:45","08:00", "08:15", "08:30", "08:45","09:00", "09:15", "09:30", "09:45","10:00", "10:15", "10:30", "10:45","11:00", "11:15", "11:30", "11:45","12:00", "12:15", "12:30", "12:45","13:00", "13:15", "13:30", "13:45","14:00", "14:15", "14:30", "14:45","15:00", "15:15", "15:30", "15:45","16:00", "16:15", "16:30", "16:45","17:00", "17:15", "17:30", "17:45","18:00", "18:15", "18:30", "18:45","19:00", "19:15", "19:30", "19:45","20:00", "20:15", "20:30", "20:45","21:00", "21:15", "21:30", "21:45","22:00", "22:15", "22:30", "22:45","23:00", "23:15", "23:30", "23:45");
choicehowpieces.getItems().addAll("Ampullen", "Esslöffel", "Gramm", "Injektion", "Kapsel", "Milligramm", "Milliliter", "Packung", "Tabletten", "Teelöffel", "Tropfen", "Zäpfchen");
choicetaking.getItems().addAll("Auflösen", "Fette", "Flüssigkeit", "Trocken");
}
}[/CODE]
Die Einträge für die Tabelle läuft über meine Model-Klasse medList:
[CODE lang="java" title="medList (Model)"]package sample;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class medList {
public StringProperty med;
public void setMed(String value){ medProperty().set(value); }
public String getMed(){ return medProperty().get(); }
public StringProperty medProperty(){
if (med == null) med = new SimpleStringProperty(this, "medizinEingabe");
return med;
}
public StringProperty menge;
public void setMenge(String value){ mengeProperty().set(value); }
public String getMenge(){ return mengeProperty().get(); }
public StringProperty mengeProperty(){
if (menge == null) menge = new SimpleStringProperty(this, "mengenEingabe");
return menge;
}
public StringProperty einnahme;
public void setEinnahme(String value){ einnahmeProperty().set(value); }
public String getEinnahme(){ return einnahmeProperty().get(); }
public StringProperty einnahmeProperty(){
if (einnahme == null) einnahme = new SimpleStringProperty(this, "einnahmenEingabe");
return einnahme;
}
public StringProperty uhr;
public void setUhr(String value){ uhrProperty().set(value); }
public String getUhr(){ return uhrProperty().get(); }
public StringProperty uhrProperty(){
if (uhr == null) uhr = new SimpleStringProperty(this, "uhrZeit");
return uhr;
}
}
[/CODE]
Ich habe mir schon verschiedene ähnliche Probleme angesehen, aber keine der Lösungen traf auf mein Programm zu.