I've created a program for charts, and I get exception in the pointed string. But actually, no any one line of my code is mentioned in exception, and there is no obvious reason for this.
Code:
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class JavaCharts extends Application {
public static void main(String[] args) {
launch(args);
}
NumberAxis axis1 = new NumberAxis(0, 100, 10);
NumberAxis axis2 = new NumberAxis(0, 100, 10);
LineChart testedLineChart = new LineChart(axis1, axis2);
VBox vb = new VBox();
@Override
public void start(Stage stage) throws Exception {
testedLineChart.setTitle("LineChart");
testedLineChart.setStyle("-fx-border-color: darkgray;");
ObservableList list = FXCollections.observableArrayList();
int max = 100;
int min = 30;
for (int i = 0; i < 30; i++) {
XYChart.Data newData = new XYChart.Data();
newData.setXValue(new Random().nextDouble() * (max - min) + min);
newData.setYValue(new Random().nextDouble() * (max - min) + min);
list.add(newData);
}
Object[] array = list.toArray();
Arrays.sort(array, new Comparator() {
@Override
public int compare(Object t, Object t1) {
return (int) Math.round(((Double) ((XYChart.Data) t).getXValue()) - ((Double) ((XYChart.Data) t1).getXValue()));
}
});
XYChart.Series serie = new XYChart.Series("serie", FXCollections.observableArrayList(array));
testedLineChart.getData().add(serie);
testedLineChart.setAlternativeColumnFillVisible(true);
testedLineChart.setAlternativeRowFillVisible(true);
Pane pane = new Pane();
pane.setPrefSize(600, 600);
TextField tf = new TextField("Text");
//axis1.labelProperty().bindBidirectional(tf.textProperty());//Doesn't throw exception
tf.textProperty().bindBidirectional(axis1.labelProperty());//Throw exception
pane.setPrefSize(600, 600);
pane.getChildren().add(testedLineChart);
vb.getChildren().addAll(pane, tf);
Scene scene = new Scene(vb, 700, 700);
stage.setScene(scene);
stage.show();
}
}
To reproduce - type in any text.
Exception:
java.lang.NullPointerException
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.defaultKeyTyped(TextInputControlBehavior.java:219)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:129)
at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:157)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callActionForEvent(TextInputControlBehavior.java:117)
at com.sun.javafx.scene.control.behavior.BehaviorBase$1.handle(BehaviorBase.java:121)
at com.sun.javafx.scene.control.behavior.BehaviorBase$1.handle(BehaviorBase.java:119)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$KeyHandler.process(Scene.java:3478)
at javafx.scene.Scene$KeyHandler.access$2300(Scene.java:3433)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:1865)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2231)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:126)
at com.sun.glass.ui.View.handleKeyEvent(View.java:518)
at com.sun.glass.ui.View.notifyKey(View.java:951)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
at java.lang.Thread.run(Thread.java:722)
Code:
import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class JavaCharts extends Application {
public static void main(String[] args) {
launch(args);
}
NumberAxis axis1 = new NumberAxis(0, 100, 10);
NumberAxis axis2 = new NumberAxis(0, 100, 10);
LineChart testedLineChart = new LineChart(axis1, axis2);
VBox vb = new VBox();
@Override
public void start(Stage stage) throws Exception {
testedLineChart.setTitle("LineChart");
testedLineChart.setStyle("-fx-border-color: darkgray;");
ObservableList list = FXCollections.observableArrayList();
int max = 100;
int min = 30;
for (int i = 0; i < 30; i++) {
XYChart.Data newData = new XYChart.Data();
newData.setXValue(new Random().nextDouble() * (max - min) + min);
newData.setYValue(new Random().nextDouble() * (max - min) + min);
list.add(newData);
}
Object[] array = list.toArray();
Arrays.sort(array, new Comparator() {
@Override
public int compare(Object t, Object t1) {
return (int) Math.round(((Double) ((XYChart.Data) t).getXValue()) - ((Double) ((XYChart.Data) t1).getXValue()));
}
});
XYChart.Series serie = new XYChart.Series("serie", FXCollections.observableArrayList(array));
testedLineChart.getData().add(serie);
testedLineChart.setAlternativeColumnFillVisible(true);
testedLineChart.setAlternativeRowFillVisible(true);
Pane pane = new Pane();
pane.setPrefSize(600, 600);
TextField tf = new TextField("Text");
//axis1.labelProperty().bindBidirectional(tf.textProperty());//Doesn't throw exception
tf.textProperty().bindBidirectional(axis1.labelProperty());//Throw exception
pane.setPrefSize(600, 600);
pane.getChildren().add(testedLineChart);
vb.getChildren().addAll(pane, tf);
Scene scene = new Scene(vb, 700, 700);
stage.setScene(scene);
stage.show();
}
}
To reproduce - type in any text.
Exception:
java.lang.NullPointerException
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.defaultKeyTyped(TextInputControlBehavior.java:219)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callAction(TextInputControlBehavior.java:129)
at com.sun.javafx.scene.control.behavior.BehaviorBase.callActionForEvent(BehaviorBase.java:157)
at com.sun.javafx.scene.control.behavior.TextInputControlBehavior.callActionForEvent(TextInputControlBehavior.java:117)
at com.sun.javafx.scene.control.behavior.BehaviorBase$1.handle(BehaviorBase.java:121)
at com.sun.javafx.scene.control.behavior.BehaviorBase$1.handle(BehaviorBase.java:119)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$KeyHandler.process(Scene.java:3478)
at javafx.scene.Scene$KeyHandler.access$2300(Scene.java:3433)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:1865)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2231)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:126)
at com.sun.glass.ui.View.handleKeyEvent(View.java:518)
at com.sun.glass.ui.View.notifyKey(View.java:951)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
at java.lang.Thread.run(Thread.java:722)
- duplicates
-
JDK-8127774 TextField with bidirectional binding is not editable in applet but editable in standalone execution mode
- Closed