1

自版本 4 以来我就没有使用过 java,并且铸造接缝已经改变到几乎令人讨厌的地步。我不明白如何处理以下编译错误。

HelloWorld.java:70: 错误:没有找到适合 add(Series) lineChart.getData().add(series) 的方法;^ 方法 List.add(int,Series) 不适用(实际参数列表和形式参数列表长度不同) 方法 List.add(Series) 不适用(实际参数 Series 无法通过方法调用转换转换为 Series)

这是我的代码:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.*;
import javafx.stage.Stage;
import javafx.geometry.Side;
import java.lang.*;
import java.net.*; 
import java.io.*;
import java.util.*;




public class HelloWorld extends Application {

    @Override public void start(Stage stage) {


        Vector <String[]>  v = new Vector<String[]>();

        try{

                File f = new File("audjpy.txt"); 
                BufferedReader br = new BufferedReader(new FileReader(f));
                String line;
                String[] data;
                int count = 0;
                while ((line = br.readLine()) != null) {
                        data = line.split(",");
                        if(count>0)v.add(data);
                        if(count == 400)break;
                        count++;
                }
                br.close();
        }catch(IOException e){System.out.println(e);}




        stage.setTitle("Line Chart Sample");
        //defining the axes
        NumberAxis xAxis = new NumberAxis();
        NumberAxis yAxis = new NumberAxis();
        yAxis.setSide(Side.RIGHT);
        xAxis.setLabel("Number of Month");
        //creating the chart
        final LineChart<Number,Number> lineChart = 
                new LineChart<Number,Number>(xAxis,yAxis);

        lineChart.setTitle("Stock Monitoring, 2010");

        //defining a series
        XYChart.Series<Double, Double> series = new XYChart.Series<Double, Double>();
        series.setName("My portfolio");

        //populating the series with data
        //<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
    Enumeration<String[]> e = v.elements();
    while(e.hasMoreElements()){
        String[] data = e.nextElement();
            double x = Double.parseDouble(data[4]);
            double y = Double.parseDouble(data[5]);
            series.getData().add(new XYChart.Data<Double, Double>(x,y));
        }

        Scene scene  = new Scene(lineChart,800,600);
        lineChart.getData().add(1, series);

        stage.setScene(scene);
        stage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}
4

1 回答 1

0

原因似乎是因为您正在使用Double并且Number可以互换,将每个泛型更改为Number并且您的问题应该得到解决。

@Override
public void start(Stage stage) {


    Vector<String[]> v = new Vector<String[]>();

    try {

        File f = new File("audjpy.txt");
        BufferedReader br = new BufferedReader(new FileReader(f));
        String line;
        String[] data;
        int count = 0;
        while ((line = br.readLine()) != null) {
            data = line.split(",");
            if (count > 0) {
                v.add(data);
            }
            if (count == 400) {
                break;
            }
            count++;
        }
        br.close();
    } catch (IOException e) {
        System.out.println(e);
    }




    stage.setTitle("Line Chart Sample");
    //defining the axes
    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();
    yAxis.setSide(Side.RIGHT);
    xAxis.setLabel("Number of Month");
    //creating the chart
    final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);

    lineChart.setTitle("Stock Monitoring, 2010");

    //defining a series
    XYChart.Series<Number, Number> series = new XYChart.Series<Number, Number>();
    series.setName("My portfolio");

    //populating the series with data
    //<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
    Enumeration<String[]> e = v.elements();
    while (e.hasMoreElements()) {
        String[] data = e.nextElement();
        double x = Double.parseDouble(data[4]);
        double y = Double.parseDouble(data[5]);
        series.getData().add(new XYChart.Data<Number, Number>(x,y));
    }

    Scene scene = new Scene(lineChart, 800, 600);
    lineChart.getData().add(1, series);

    stage.setScene(scene);
    stage.show();
}
于 2013-01-08T17:42:04.187 回答