2

I'm writing a program on the desktop that takes an array of COM port and displays it on the chart dynamically. the program runs without failures for a while, but then fails with the following exception:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:344)
at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:267)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:521)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:505)
at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$399(QuantumToolkit.java:334)
at com.sun.javafx.tk.quantum.QuantumToolkit$$Lambda$40/432581434.run(Unknown Source)
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$144(WinApplication.java:101)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/1963387170.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)

the application continues to run. continue to saved data to a text file, but the window is not active any button except the close button. if anyone has any ideas please help.

here is some code

public class FXMLController implements Initializable {

public static XYChart.Series<Number, Number> hourDataSeries;

@FXML
public Label label;
@FXML
public Label statusbar;
@FXML
public LineChart lineChart;
@FXML
public NumberAxis xAxis;
@FXML
NumberAxis yAxis;
@FXML
MenuItem close;
@FXML
MenuItem Options;
@FXML
MenuItem about;
@FXML
Button connect;
@FXML
public Label hexString;

@FXML
private void close(ActionEvent event) throws SerialPortException {
    //COMConnect.serialPort.closePort();
    System.exit(0);
}

@FXML
private void connect(ActionEvent event) {
    OpenScene openScene = new OpenScene("/SceneCOM.fxml", "Options");
}

@FXML
private void showStatistics(ActionEvent event) {
    OpenScene openScene = new OpenScene("/SceneStatistics.fxml", "Statistics");
}

@FXML
private void aboutit(ActionEvent event) {
    OpenScene openScene = new OpenScene("/SceneAbout.fxml", "About");
}

@FXML
private void getconnect(ActionEvent event) {

    if (COMConnect.b == true) {
        COMConnect.b = false;
        try {
            COMConnect.serialPort.closePort();
        } catch (SerialPortException ex) {
            Logger.getLogger(FXMLController.class.getName()).log(Level.SEVERE, null, ex);
        }
        connect.setText("Connect");
    } else {
        COMConnect.b = true;
        COMConnect.comConnect();

    }

}

@Override
public void initialize(URL url, ResourceBundle rb) {

    hourDataSeries = new XYChart.Series<Number, Number>();
    label.textProperty().bind(COMConnect.EventListener.valueProperty);
    COMConnect.connectProperty.setValue("Connect");
    connect.textProperty().bindBidirectional(COMConnect.connectProperty);
    statusbar.textProperty().bind(Typewriter.status);
    hexString.textProperty().bind(TypewriterHexString.hexStr);
    xAxis.setLabel("Time");
    xAxis.setTickUnit(1);
    xAxis.setTickLabelFormatter(new NSC());
    yAxis.setLabel("density," + superscript(" kg/m3"));

    xAxis.setForceZeroInRange(false);
    lineChart.setLegendVisible(false);
    lineChart.setCursor(Cursor.CROSSHAIR);
    lineChart.getData().add(hourDataSeries);

}

}

and add data to LineChart from other class

javafx.application.Platform.runLater(new Runnable() {
                        @Override
                        public void run() {

                            valueProperty.setValue(formatt(second) + superscript(" kg/m3"));

                            if (y > 10) {
                                hourDataSeries.getData().remove(0);

                            }
                            data = new XYChart.Data<Number, Number>(y, second);
                            data.setNode(new HoveredThresholdNode(0, second, ""));
                            hourDataSeries.getData().add(data);
                            System.out.println(hourDataSeries.getData().toString());
                            y++;
                        }
                    });
                }
7
  • Share some code, otherwise is not possible to see what's going on Commented Dec 17, 2014 at 10:06
  • @JoséPereda The program receives data from the COM port every 22 seconds. last received data 720 times before the error. and then I got this exception. I am afraid that this is a bug in jre Commented Dec 17, 2014 at 10:33
  • What serial library are you using? Commented Dec 17, 2014 at 10:44
  • @JoséPereda jssc 2.8.0 code.google.com/p/java-simple-serial-connector Commented Dec 17, 2014 at 10:55
  • 1
    You can find an example of plotting data coming from serial port in the book JavaFX 8 Introduction by Example. Commented Dec 17, 2014 at 11:38

1 Answer 1

1

Thus, the solution was very simple:

lineChart.setAnimated(false);

the application works correctly for about 25 hours. Thanks everyone!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.