JavaFX测试在Windows中失败并在OSX和Linux中运行 [英] JavaFX Test That fails in Windows and works in OSX and Linux

查看:385
本文介绍了JavaFX测试在Windows中失败并在OSX和Linux中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JavaFX测试仅在Windows中失败,但在OSX和Linux中运行良好

I have a JavaFX test that fails only in windows , but works fine in OSX and Linux

这是堆栈跟踪:


编辑:1

Edit : 1



Running com.myproject.meditor.SLIVCodeAreaTest
Tests run: 17, Failures: 0, Errors: 17, Skipped: 0, Time elapsed: 6.656 sec <<< FAILURE! - in com.myproject.meditor.SLIVCodeAreaTest
testRHBlock(com.myproject.meditor.SLIVCodeAreaTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.ExceptionInInitializerError: null
    at com.sun.glass.ui.Screen.getScreens(Screen.java:70)
    at com.sun.glass.ui.Screen.getMainScreen(Screen.java:61)
    at com.sun.javafx.font.PrismFontFactory.getSystemFontSize(PrismFontFactory.java:1911)
    at com.sun.javafx.font.PrismFontLoader.getSystemFontSize(PrismFontLoader.java:240)
    at javafx.scene.text.Font.getDefaultSystemFontSize(Font.java:71)
    at javafx.scene.text.Font.getDefault(Font.java:86)
    at javafx.scene.text.Text.getFont(Text.java:478)
    at javafx.scene.text.Text.getFontInternal(Text.java:487)
    at javafx.scene.text.Text.access$100(Text.java:95)
    at javafx.scene.text.Text$1.getFont(Text.java:206)
    at com.sun.javafx.text.GlyphLayout.breakRuns(GlyphLayout.java:174)
    at com.sun.javafx.text.PrismTextLayout.buildRuns(PrismTextLayout.java:770)
    at com.sun.javafx.text.PrismTextLayout.layout(PrismTextLayout.java:1021)
    at com.sun.javafx.text.PrismTextLayout.ensureLayout(PrismTextLayout.java:223)
    at com.sun.javafx.text.PrismTextLayout.getBounds(PrismTextLayout.java:246)
    at javafx.scene.text.TextFlow.computePrefWidth(TextFlow.java:203)
    at javafx.scene.Parent.prefWidth(Parent.java:915)
    at javafx.scene.layout.Region.prefWidth(Region.java:1419)
    at org.fxmisc.richtext.ParagraphBox.computePrefWidth(ParagraphBox.java:199)
    at org.fxmisc.richtext.ParagraphBox.computeMinWidth(ParagraphBox.java:191)
    at javafx.scene.Parent.minWidth(Parent.java:943)
    at javafx.scene.layout.Region.minWidth(Region.java:1383)
    at org.fxmisc.flowless.VerticalHelper.minBreadth(OrientationHelper.java:234)
    at org.fxmisc.flowless.OrientationHelper.minBreadth(OrientationHelper.java:44)
    at org.reactfx.collection.MappedList.get(MappedList.java:27)
    at org.reactfx.collection.MemoizationListImpl.force(MemoizationList.java:121)
    at org.fxmisc.flowless.SizeTracker.breadthFor(SizeTracker.java:161)
    at org.fxmisc.flowless.CellPositioner.getSizedCell(CellPositioner.java:130)
    at org.fxmisc.flowless.CellPositioner.placeStartAt(CellPositioner.java:95)
    at org.fxmisc.flowless.Navigator.placeStartAtMayCrop(Navigator.java:183)
    at org.fxmisc.flowless.Navigator.visit(Navigator.java:111)
    at org.fxmisc.flowless.StartOffStart.accept(TargetPosition.java:49)
    at org.fxmisc.flowless.Navigator.layoutChildren(Navigator.java:67)
    at javafx.scene.Parent.layout(Parent.java:1087)
    at org.fxmisc.flowless.VirtualFlow.layoutChildren(VirtualFlow.java:165)
    at javafx.scene.Parent.layout(Parent.java:1087)
    at org.fxmisc.flowless.VirtualFlow.visibleCells(VirtualFlow.java:138)
    at com.myproject.util.javafx.codearea.SEditor.<init>(SEditor.java:659)
    at com.myproject.util.javafx.codearea.SEditor.<init>(SEditor.java:607)
    at com.myproject.util.javafx.codearea.SCodeArea.<init>(SCodeArea.java:122)
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:124)
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:114)
    at com.myproject.meditor.SLItemCodeArea.<init>(SLICodeArea.java:106)
    at com.myproject.meditor.SLItemCodeArea.<init>(SLICodeArea.java:103)
    at com.myproject.meditor.SLIVCodeAreaTest.<clinit>(SLIVCodeAreaTest.java:14)




编辑:2

2

从堆栈跟踪中,触发异常(SLIVCodeAreaTest.java:14)的代码部分位于私有静态final的声明中SLIVCodeArea 代码部分:

From the stack trace, the part of code that triggered the exception (SLIVCodeAreaTest.java:14) is in the declaration of private static final SLIVCodeArea in the part of code :

import static org.junit.Assert.assertTrue;
import org.junit.Test;

public class SLIVCodeAreaTest {     
    private static final SLIVCodeArea sEditor = new SLIVCodeArea(new SLICodeArea()) {

        @Override protected void updateVisibleParagraphRange() {}   };

    private static final VEditorProblemList sProblemList = 
        new VEditorProblemList(sEditor, new SimpleObjectProperty<>(), false);

    static { sEditor.aggregatedTextChanges().setAggregationEnabled(false); }




编辑:3

Edit : 3

如果我从上面的初始化部分删除关键字 static ,则错误的堆栈跟踪将变为:

If I remove the keyword static from the initialisation part above , the stacktrace of the error becomes :

Running com.myproject.meditor.SLIVCodeAreaTest
Tests run: 17, Failures: 0, Errors: 17, Skipped: 0, Time elapsed: 1.124 sec <<< FAILURE! - in Running com.myproject.meditor.SLIVCodeAreaTest
testRHBlock(com.myproject.meditor.SLIVCodeAreaTest)  Time elapsed: 0 sec  <<< ERROR!
java.lang.RuntimeException: Internal graphics not initialized yet
    at com.sun.glass.ui.Screen.getScreens(Screen.java:70)
    at com.sun.glass.ui.Screen.getMainScreen(Screen.java:61)
    at com.sun.javafx.font.PrismFontFactory.getSystemFontSize(PrismFontFactory.java:1911)
    at com.sun.javafx.font.PrismFontLoader.getSystemFontSize(PrismFontLoader.java:240)
    at javafx.scene.text.Font.getDefaultSystemFontSize(Font.java:71)
    at javafx.scene.text.Font.getDefault(Font.java:86)
    at javafx.scene.text.Text.getFont(Text.java:478)
    at javafx.scene.text.Text.getFontInternal(Text.java:487)
    at javafx.scene.text.Text.access$100(Text.java:95)
    at javafx.scene.text.Text$1.getFont(Text.java:206)
    at com.sun.javafx.text.GlyphLayout.breakRuns(GlyphLayout.java:174)
    at com.sun.javafx.text.PrismTextLayout.buildRuns(PrismTextLayout.java:770)
    at com.sun.javafx.text.PrismTextLayout.layout(PrismTextLayout.java:1021)
    at com.sun.javafx.text.PrismTextLayout.ensureLayout(PrismTextLayout.java:223)
    at com.sun.javafx.text.PrismTextLayout.getBounds(PrismTextLayout.java:246)
    at javafx.scene.text.TextFlow.computePrefWidth(TextFlow.java:203)
    at javafx.scene.Parent.prefWidth(Parent.java:915)
    at javafx.scene.layout.Region.prefWidth(Region.java:1419)
    at org.fxmisc.richtext.ParagraphBox.computePrefWidth(ParagraphBox.java:199)
    at org.fxmisc.richtext.ParagraphBox.computeMinWidth(ParagraphBox.java:191)
    at javafx.scene.Parent.minWidth(Parent.java:943)
    at javafx.scene.layout.Region.minWidth(Region.java:1383)
    at org.fxmisc.flowless.VerticalHelper.minBreadth(OrientationHelper.java:234)
    at org.fxmisc.flowless.OrientationHelper.minBreadth(OrientationHelper.java:44)
    at org.reactfx.collection.MappedList.get(MappedList.java:27)
    at org.reactfx.collection.MemoizationListImpl.force(MemoizationList.java:121)
    at org.fxmisc.flowless.SizeTracker.breadthFor(SizeTracker.java:161)
    at org.fxmisc.flowless.CellPositioner.getSizedCell(CellPositioner.java:130)
    at org.fxmisc.flowless.CellPositioner.placeStartAt(CellPositioner.java:95)
    at org.fxmisc.flowless.Navigator.placeStartAtMayCrop(Navigator.java:183)
    at org.fxmisc.flowless.Navigator.visit(Navigator.java:111)
    at org.fxmisc.flowless.StartOffStart.accept(TargetPosition.java:49)
    at org.fxmisc.flowless.Navigator.layoutChildren(Navigator.java:67)
    at javafx.scene.Parent.layout(Parent.java:1087)
    at org.fxmisc.flowless.VirtualFlow.layoutChildren(VirtualFlow.java:165)
    at javafx.scene.Parent.layout(Parent.java:1087)
    at org.fxmisc.flowless.VirtualFlow.visibleCells(VirtualFlow.java:138)
    at com.myproject.util.javafx.codearea.SEditor.<init>(SEditor.java:659)
    at com.myproject.util.javafx.codearea.SEditor.<init>(SEditor.java:607)
    at com.myproject.util.javafx.codearea.SCodeArea.<init>(SCodeArea.java:122)
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:124)
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:114)
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:106)
    at com.myproject.meditor.SLICodeArea.<init>(SLICodeArea.java:103)
    at com.myproject.meditor.SLIVCodeAreaTest.<init>(SLIVCodeAreaTest.java:14)




PS:测试在OSX中有和没有 static 关键字。

PS : The test worked in OSX with and without static keyword.

相同的代码在Linux和MacOS中运行良好,但在Windows中失败。
有没有人知道为什么?

The same code works fine in Linux and MacOS, but fails in windows. Does anyone have an idea why ?

推荐答案

根据 Class ExceptionInInitializerError


公共类ExceptionInInitializerError扩展了LinkageError信号
静态初始值设定项中发生了意外异常。抛出
ExceptionInInitializerError以指示在评估静态初始化程序期间发生异常
或初始化程序
为静态变量。

public class ExceptionInInitializerError extends LinkageError Signals that an unexpected exception has occurred in a static initializer. An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.

因为你没有发布最小,完整,以及可验证的示例。
我认为因为 newscreens 不是静态或是由 null ,并且您尝试将 null 变量传输到数组。

Because you did not post a Minimal, Complete, and Verifiable example. I think because newscreens is not static or is initialized by null,and you tried to transfer nullvariable to array.

这篇关于JavaFX测试在Windows中失败并在OSX和Linux中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆