字符串不能应用于com.org.apache.xpath.internal.operations.String [英] String cannot be applied to com.org.apache.xpath.internal.operations.String
问题描述
我正在尝试在JavaFX中创建一个PieChart
,我想用HashMap
中的数据填充它.
I'm trying to create a PieChart
in JavaFX, and I want to fill it with data from a HashMap
.
这是我的代码:
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()
作为字符串时,出现以下错误:
The issue I am facing is that when I try to use entry.getKey()
as the string, I get the following error:
Data中的数据(java.lang.String,双精度)不能应用于 (com.org.apache.xpath.internal.operations.String,Double).
Data (java.lang.String, double) in Data cannot be applied to (com.org.apache.xpath.internal.operations.String, Double).
该字符串标记为红色,当我将entry.getKey()
替换为"Some text"
时,它确实起作用.是什么原因?
The String is marked red and when I replace entry.getKey()
with "Some text"
it does work. What is the cause?
推荐答案
您似乎在当前文件中导入了错误的"String"类(com.org.apache.xpath.internal.operations.String
),而Data类期望使用正确的(String)类(java.lang.String
) .确保您的导入正确无误(即删除第一种类型的导入).
You seem to have imported the wrong "String" class ( com.org.apache.xpath.internal.operations.String
) in your current file and the Data class expects the correct one (java.lang.String
). Make sure your imports are correct (i.e. remove the import of the first type).
另请参见此问题,询问者在哪里遇到了类似的问题
Also see this question, where the asker has run into a similar problem
这篇关于字符串不能应用于com.org.apache.xpath.internal.operations.String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!