2017-09-03 148 views
-1

工作我有一个JavaFX测试失败仅适用于Windows,但在OSX和LinuxJavaFX的测试失败,在Windows和OSX和Linux

这里工作正常是堆栈跟踪:

编辑: 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

从堆栈跟踪,触发异常(SLIVCodeAreaTest.java:14)处于private static final SLIVCodeArea在代码的部分声明的代码部分:

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

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

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工作与不静态关键字。

相同的代码在Linux和MacOS中工作正常,但在Windows中失败。 有没有人有一个想法,为什么?

+1

创建并发布[MCVE]。 –

+0

请在您的问题中包含* entire *堆栈跟踪。你调用哪行代码触发了异常? – VGR

+0

屏幕是一个全局或局部变量?我认为你的方法_staticScreaan_getScreens_返回null,所以你的表有空元素。 –

回答

0

JavaFX,JUnit和任何java.lang.ExceptionInInitializerError的组合是抑制异常Toolkit not initialized发生的指标。

要初始化JavaFX,您可以在运行单元测试之前等待new JFXPanel()完成。

参见:

+0

如果发生异常_Toolkit未初始化,为什么它不会在MacOS或Linux中发生? – josephino

+0

可能取决于MacOS,Linux或Windows上使用的JRE版本。 – 2017-09-03 19:18:44

+0

什么是异常的“抑制事件”?是什么让你相信这是一个未初始化的JavaFX应用程序的症状?我在链接的SO问题中没有看到任何提到问题堆栈跟踪中的任何类的问题。 – VGR

0

根据Class ExceptionInInitializerError

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

因为你没有张贴 Minimal, Complete, and Verifiable example. 我想是因为newscreens不是静态或由初始化,你试图null变量转移到阵列。

+0

由于存在很多依赖关系,因此无法生成最小完整示例,您对静态初始化程序评估过程中发生异常这一事实是正确的,请参阅上面的编辑 – josephino