There are a lot of demo programs for JavaFX graphics features like the following one for a JavaFX LineChart:
public class LineChartSample extends Application {@Override public void start(Stage stage) {
stage.setTitle("Line Chart Sample");
//defining the axes
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
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 series = new XYChart.Series();
series.setName("My portfolio");
//populating the series with data
series.getData().add(new XYChart.Data(1, 23));
series.getData().add(new XYChart.Data(2, 14));
//etc..
Scene scene = new Scene(lineChart,800,600);
lineChart.getData().add(series);
stage.setScene(scene);
stage.show();
}public static void main(String[] args) {
launch(args);
}
The limiting factor for me is the data pairs have to be hard-coded before the application works. I would instead like to populate the line chart with data read from an external file, which in my case is an Excel spreadsheet containing numerical data.
This data is retrieved as an ArrayList of doubles. The method for getting the data is in another package, and works without error in other applications. The method is called like this:
private ArrayList<Double> teamstats;
...
teamstats = ExcelManager.getTeamMavgStats("D1", "Arsenal");
//iterate on teamstats to populate the series...
However when I introduce the above line of code to begin to replace the hard coded getData().add calls, I get the following error when trying to run the program from Netbeans 8.0.2:
run:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl. java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImp l.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl. java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java: 917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$156(Launcher Impl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at movavg.excel.ExcelManager.getTeamMavgStats(ExcelManager.java:163)
at movavg.ui.LineChartSample.start(LineChartSample.java:73)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(Launche rImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.ja va:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295 )
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java :294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java: 95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
... 1 more
Exception running application movavg.ui.LineChartSample
Java Result: 1
I find it hard to know what to do about this as I have never encountered this kind of exception before.