Это из основного класса графического интерфейса «miniPaint»
Код: Выделить всё
if (drawButt.isSelected() == true&& shapesCombo.getValue() == "Line") {
pane.setOnMousePressed(m->{
Line line = new Line();
line.setStroke(currentColor.getFill());
line.setStartX(m.getSceneX());
line.setStartY(m.getSceneY());
pane.getChildren().add(line);
pane.setOnMouseDragged(q ->{
line.setEndX(q.getSceneX());
line.setEndY(q.getSceneY());
pane.setOnMouseReleased(a->{
collector.addShape(line);
});
});
});
}
Код: Выделить всё
public class ShapeCollection {
private ArrayList lines;
private ArrayList rectangles;
private ArrayList ellipses;
public ShapeCollection() {
ArrayList lines = new ArrayList();
ArrayList rectangles = new ArrayList();
ArrayList ellipses = new ArrayList();
}
public void addShape(Shape shape) {
if (shape instanceof Line) {
lines.add((Line) shape);
}
if (shape instanceof Rectangle) {
rectangles.add((Rectangle) shape);
}
if (shape instanceof Ellipse) {
ellipses.add((Ellipse) shape);
}
}
Код: Выделить всё
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot invoke "java.util.ArrayList.add(Object)" because "this.lines" is null
at Project3/application.ShapeCollection.addShape(ShapeCollection.java:22)
at Project3/application.MiniPaint.lambda$6(MiniPaint.java:98)
Подробнее здесь: https://stackoverflow.com/questions/784 ... ption-in-t