我从版本4开始就没有使用java,并且接缝已经改变到几乎令人讨厌的程度。我不明白如何处理以下编译错误。
HelloWorld.java:70:错误:找不到合适的方法 添加(系列) 。lineChart.getData()添加(系列); ^ 方法List.add(int,Series)不适用 (实际和正式的参数列表长度不同) 方法List.add(系列)不适用 (实际参数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);
}
}
答案 0 :(得分: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();
}