您好我真的希望有人可以帮助我。 我有一个选择框和一个用于打印国家桌子的方法。 pdfCountry需要一个国家名称作为String来做某事。
代码方法:
public void pdfCountry(String countryName) {
HashMap<String, String> country = new HashMap<String, String>();
HashMap<String, String> co2String = new HashMap<String, String>();
for( Integer key2 : csv.co2.keySet()) {
co2String.put(key2.toString(), csv.co2.get(key2).toString());
}
for(Integer key: csv.yearlyTempByCountry.get(countryName).keySet()) {
country.put(key.toString(), csv.yearlyTempByCountry.get(countryName).get(key).toString());
}
pdf.printPDF(country, co2String);
}
代码:choicebox
private void getChoice(ChoiceBox<String> choicebox) {
// TODO Auto-generated method stub
Stage primaryStage = new Stage();
primaryStage.setTitle("Länder Liste");
Label land= new Label("Welches Land soll exportiert werden?");
Button test= new Button("pdf");
VBox auswahl = new VBox();
choicebox= new ChoiceBox<>();
choicebox.getItems().addAll("United Arab Emirates","Angola","Argentina", "Austria","Australia", "Azerbaijan","Bosnia And Herzegovin", "Bangladesh", "Belgium", "Burkina Faso", "Bulgaria", "Burundi","Benin","Brunei Darussalam","Bolivia","Brazil", "Bahamas", "Bhutan","Botswana","Belarus", "Belize","Canada","Congo (Democratic Republic Of The)");
test.setOnAction(e -> pdfCountry("Germany")); // works perfectly fine
但我只是想在应用中选择一个国家/地区,pdfCountry就是正确的
国家自动。
例如:test.setOnAction(e -> pdfCountry(choicebox.getvalue()));
总是最后的错误,我不知道如何解决它。