我試圖在JavaFX中創建一個PieChart
,我想用HashMap
中的數據填充它。字符串不能應用於com.org.apache.xpath.internal.operations.String
這裏是我的代碼:
public Graph(HashMap<String, Double> chartData) {
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList();
for (Map.Entry<String, Double> entry: chartData.entrySet()) {
String s = entry.getKey();
new PieChart.Data(entry.getKey(), entry.getValue());
//System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
chart = new PieChart(pieChartData);
chart.setTitle("Imported Fruits");
}
我現在面臨的問題是,當我嘗試使用entry.getKey()
爲字符串,我得到以下錯誤:
Data (java.lang.String, double) in Data cannot be applied to (com.org.apache.xpath.internal.operations.String, Double).
的字符串標記紅色當我用"Some text"
代替entry.getKey()
它確實有效。原因是什麼?
謝謝,一定是進口本身,它沒有被注意到。 –
如果我的猜測是正確的,接受答案:) – wonderb0lt
是的,我會的,不能在15分鐘內完成;) –