Код: Выделить всё
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:465)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1082)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NullPointerException: Cannot invoke "javafx.scene.Node.setStyle(String)" because the return value of "javafx.scene.Node.lookup(String)" is null
at com.example.lab2_int/com.example.lab2_int.HelloApplication.start(HelloApplication.java:290)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
... 1 more
Exception running application com.example.lab2_int.HelloApplication
Код: Выделить всё
package com.example.lab3_int;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.Node;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
NumberAxis xAxis0 = new NumberAxis();
NumberAxis yAxis0 = new NumberAxis();
LineChart lineChart0 = new LineChart(xAxis0, yAxis0);
XYChart.Series exception_g = new XYChart.Series();
exception_g.setName("Exceptions");
XYChart.Series w0_g = new XYChart.Series();
w0_g.setName("w0");
XYChart.Series w1_g = new XYChart.Series();
w1_g.setName("w1");
XYChart.Series w2_g = new XYChart.Series();
w2_g.setName("w2");
XYChart.Series w3_g = new XYChart.Series();
w3_g.setName("w3");
exception_g.getData().add(new XYChart.Data(0,7));
exception_g.getData().add(new XYChart.Data(1,17));
exception_g.getData().add(new XYChart.Data(2,-2));
w0_g.getData().add(new XYChart.Data(0,11));
w0_g.getData().add(new XYChart.Data(1,6));
w0_g.getData().add(new XYChart.Data(2,0));
w1_g.getData().add(new XYChart.Data(0,-7));
w1_g.getData().add(new XYChart.Data(1,9));
w1_g.getData().add(new XYChart.Data(2,13));
w2_g.getData().add(new XYChart.Data(0,9));
w2_g.getData().add(new XYChart.Data(1,2));
w2_g.getData().add(new XYChart.Data(2,5));
w3_g.getData().add(new XYChart.Data(0,14));
w3_g.getData().add(new XYChart.Data(1,-10));
w3_g.getData().add(new XYChart.Data(2,5));
lineChart0.getStylesheets().add("/stylesheet.css");
lineChart0.getData().add(exception_g);
lineChart0.getData().add(w0_g);
lineChart0.getData().add(w1_g);
lineChart0.getData().add(w2_g);
lineChart0.getData().add(w3_g);
exception_g.getNode().lookup(".chart-series-line").setStyle("-fx-stroke: black;-fx-stroke-dash-array: 5 5;");
for (XYChart.Data data : exception_g.getData()) {
Node symbol = data.getNode().lookup(".chart-line-symbol");
symbol.setStyle("-fx-background-color: black, white;");
}
exception_g.getNode().lookup(".chart-legend").setStyle("-fx-background-color: black, white;"); //It is this line that the ide refers to.
GridPane pane = new GridPane();
pane.add(lineChart0, 0, 0);
Scene scene = new Scene(pane, 1920, 1000);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
Код: Выделить всё
.chart-series-line:{
}
.chart-line-symbol{
}
.chart-legend{
}

Возможно, есть какой-то способ изменить параметры строк прямо в css. Я попробовал использовать селектор .chart-series-line:series(0) {... в CSS с именем моей оси и идентификатором строки, но это не помогло. Или тут все не так просто и нужно в .java файле прописывать все стили. Оба решения этой проблемы будут работать.
Подробнее здесь: https://stackoverflow.com/questions/763 ... -in-javafx
Мобильная версия