我不确定为什么会出现错误?我正在使用 JFreeChart API 并尝试创建一个xy系列。我在代码下面添加了错误消息。 main方法只是调用此方法来运行它。
public class CreateGraph {
private String fileInput="F:/FunctionTrader/testFiles/test1.txt";
private XYSeries bunch=new XYSeries(null);
public void test() throws FileNotFoundException, IOException {
try (BufferedReader br = new BufferedReader(new FileReader(this.fileInput))) {
String modBarVals;
while ((modBarVals=br.readLine()) != null ){
String[] split = modBarVals.split("\\s+");
double x = Double.parseDouble(split[0]);
double y = Double.parseDouble(split[1]);
bunch.add(x,y); //error occurs here?
}
System.out.println(bunch.getItemCount());
}
}
}
异常堆栈跟踪:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.IllegalArgumentException: Null 'key' argument.
at org.jfree.chart.util.ParamChecks.nullNotPermitted(ParamChecks.java:65)
at org.jfree.data.general.Series.<init>(Series.java:120)
at org.jfree.data.general.Series.<init>(Series.java:110)
at org.jfree.data.xy.XYSeries.<init>(XYSeries.java:172)
at org.jfree.data.xy.XYSeries.<init>(XYSeries.java:145)
at IO2x.CreateGraph.<init>(CreateGraph.java:17)
at IO2x.MainClass.<clinit>(MainClass.java:17)
答案 0 :(得分:0)
堆栈跟踪告诉您,您无法在for null
中使用XYSeries
Comparable
key。你可以用
private XYSeries bunch = new XYSeries("My Data");