Im Versuch, alle Elemente in einem Arraylist zu einem javafx ComboBox hinzuzufügen, aber ich halte einen wierd Fehler bekommen,Fehler beim Hinzufügen Artikel zu comboBox JavaFX FXML
no suitable method found for add(String)
method Collection.add(CAP#1) is not applicable
(argument mismatch; String cannot be converted to CAP#1)
method List.add(CAP#1) is not applicable
(argument mismatch; String cannot be converted to CAP#1)
where CAP#1 is a fresh type-variable:
CAP#1 extends Object from capture of ?
Java-Code
File fJSon = new File("roomDetails.json");
JSONParser parser = new JSONParser();
try{
Object obj = parser.parse(new FileReader("roomDetails.json"));
JSONObject jsonObject = (JSONObject) obj;
List<String> itemIDS = new ArrayList<String> (jsonObject.keySet()); //gets json keys from a json oject previously defined
for (int i = 0; i < itemIDS.size(); i++) {
room_id.getItems().add(String.valueOf(i));
}
FXML Datei
<AnchorPane id="AnchorPane" prefHeight="437.0" prefWidth="600.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="pp01_cwk03.AddStaffController">
<children>
<Pane layoutX="14.0" layoutY="5.0" prefHeight="428.0"
prefWidth="593.0">
<children>
<ComboBox fx:id="room_id" layoutX="187.0" layoutY="178.0" prefHeight="25.0" prefWidth="149.0" />
</children>
</Pane>
</children>
</Pane>
</children>
roomDetails.json
{"366O":
["Room Name:CEO",
"Department Name:IT",
"Occupant Name:Charindu",
"Space Type:Office"],
"527F":
["Room Name:IT Lab",
"Department Name:IT",
"Occupant Name:Saman",
"Space Type: Library"]
}
Dieser Code, der die Schlüssel aus dem json bekommt oject arbeitet becouse ich es mir selbst mit einer for-Schleife, die die Details Array druckt getestet
List<String> itemIDS = new ArrayList<String> (jsonObject.keySet());
TATSÄCHLICH Wenn ich sogar setze,
room_id.getItems().add("Hello");
Es würde immer noch den gleichen Fehler zeigen, das Problem einige wh at scheint mit der ComboBox ich von Scenebuilder erstellt JavaFX
Dennoch i halten den gleichen Fehler:/ –
Don‘ t verwende rohe Typen. –