Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String cannot be applied to com.org.apache.xpath.internal.operations.String

I'm trying to create a PieChart in JavaFX, and I want to fill it with data from a HashMap.

Here's my code:

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");
}

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, double) in Data cannot be applied to (com.org.apache.xpath.internal.operations.String, Double).

The String is marked red and when I replace entry.getKey() with "Some text" it does work. What is the cause?

like image 768
Allum Avatar asked Jan 30 '26 02:01

Allum


1 Answers

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

like image 157
wonderb0lt Avatar answered Jan 31 '26 16:01

wonderb0lt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!