问题描述
我尝试在桌面上的 JavaFX 应用程序中使用 Gluon Maps Project。经过一些拖动和滚动程序抛出异常并停止工作。 StackTrace 如下:
java.lang.indexoutofboundsexception: Index -1 out of bounds for length 2
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:373)
at java.base/java.util.ArrayList.get(ArrayList.java:425)
at javafx.graphics/javafx.scene.Parent.updateCachedBounds(Parent.java:1704)
at javafx.graphics/javafx.scene.Parent.recomputeBounds(Parent.java:1648)
at javafx.graphics/javafx.scene.Parent.doComputeGeomBounds(Parent.java:1501)
at javafx.graphics/javafx.scene.Parent$1.doComputeGeomBounds(Parent.java:115)
at javafx.graphics/com.sun.javafx.scene.ParentHelper.computeGeomBoundsImpl(ParentHelper.java:84)
at javafx.graphics/com.sun.javafx.scene.NodeHelper.computeGeomBounds(NodeHelper.java:115)
at javafx.graphics/javafx.scene.Node.updateGeomBounds(Node.java:3847)
at javafx.graphics/javafx.scene.Node.getGeomBounds(Node.java:3809)
at javafx.graphics/javafx.scene.Node.getLocalBounds(Node.java:3757)
at javafx.graphics/javafx.scene.Node.updateTxBounds(Node.java:3911)
at javafx.graphics/javafx.scene.Node.getTransformedBounds(Node.java:3703)
at javafx.graphics/javafx.scene.Node.updateBounds(Node.java:771)
at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1835)
at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
at javafx.graphics/javafx.scene.Parent.updateBounds(Parent.java:1833)
at javafx.graphics/javafx.scene.Scene$ScenepulseListener.pulse(Scene.java:2491)
at javafx.graphics/com.sun.javafx.tk.Toolkit.lambda$runpulse$2(Toolkit.java:413)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.tk.Toolkit.runpulse(Toolkit.java:412)
at javafx.graphics/com.sun.javafx.tk.Toolkit.firepulse(Toolkit.java:439)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:563)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:543)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:536)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:342)
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:174)
at java.base/java.lang.Thread.run(Thread.java:830)
调试程序后,我在 gluon Maps Library(Source Code) 类 com.gluonhq.impl.maps.BaseMap (on GitHub) 中找到了问题,我怀疑该方法在第 518 行 (markDirty(){...}),但我不知道如何修复它。具体元素的代码为:
MainCenterPane.java
import com.gluonhq.maps.MapLayer;
import com.gluonhq.maps.MapPoint;
import com.gluonhq.maps.MapView;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Orientation;
import javafx.geometry.Point2D;
import javafx.scene.Node;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.borderpane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Pair;
public class MainCenterPane extends SplitPane {
private final MapPoint mapPoint = new MapPoint(50D,4D);
public MainCenterPane() {
this.setorientation(Orientation.VERTICAL);
this.setDividerPosition(0,0.8);
MapView map = new MapView();
PoiLayer pl = new PoiLayer();
pl.addPoint(mapPoint,new Circle(7,Color.RED));
map.addLayer(pl);
map.setZoom(3);
map.flyTo(1,mapPoint,2);
borderpane center = new borderpane(map);
this.getItems().add(center);
}
public class PoiLayer extends MapLayer {
private final ObservableList<Pair<MapPoint,Node>> points = FXCollections.observableArrayList();
public PoiLayer() {
}
public void addPoint(MapPoint p,Node icon) {
points.add(new Pair<>(p,icon));
this.getChildren().add(icon);
this.markDirty();
}
@Override
protected void layoutLayer() {
if(!Platform.isFxApplicationThread()) {
Platform.runLater(()->layoutLayer());
}
for (Pair<MapPoint,Node> candidate : points) {
MapPoint point = candidate.getKey();
Node icon = candidate.getValue();
Point2D mapPoint = getMapPoint(point.getLatitude(),point.getLongitude());
icon.setVisible(true);
icon.setTranslateX(mapPoint.getX());
icon.setTranslateY(mapPoint.getY());
}
}
}
}
感谢您的帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)