Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX测试,在Windows中失败,在OSX和Linux中工作_Java_Linux_Windows_Macos_Javafx - Fatal编程技术网

JavaFX测试,在Windows中失败,在OSX和Linux中工作

JavaFX测试,在Windows中失败,在OSX和Linux中工作,java,linux,windows,macos,javafx,Java,Linux,Windows,Macos,Javafx,我有一个JavaFX测试,它只在windows中失败,但在OSX和Linux中运行良好 以下是stacktrace: 编辑:1 编辑:3 如果我从上面的初始化部分删除关键字static,则错误的堆栈跟踪变为: Running com.myproject.meditor.SLIVCodeAreaTest Tests run: 17, Failures: 0, Errors: 17, Skipped: 0, Time elapsed: 1.124 sec <<< FAILURE!

我有一个JavaFX测试,它只在windows中失败,但在OSX和Linux中运行良好

以下是stacktrace:

编辑:1

编辑:3

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

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)
运行com.myproject.meditor.slivcodeatest

测试运行:17次,失败:0次,错误:17次,跳过:0次,所用时间:1.124秒将
JavaFX
JUnit
和any
java.lang.ExceptionInInitializeError组合在一起,表示异常
工具箱未初始化
被抑制

要初始化JavaFX,您可以等待
newjfxpanel()
完成,然后再运行单元测试

见:

根据

公共类ExceptionInInitializeError扩展LinkageError信号 静态初始值设定项中发生意外异常。一 抛出ExceptionInInitializerError以指示异常 在评估静态初始值设定项或初始值设定项时发生 对于静态变量

因为你没有发邮件
我想是因为
newscreens
不是静态的,或者是由null初始化的,并且您试图将
null
变量传输到数组。

创建并发布一个。请在您的问题中包含整个堆栈跟踪。您调用了触发异常的哪行代码?screens是全局变量还是局部变量?我认为您的方法staticScreaan_getScreens返回null,因此您的表中有null元素。@VGR请参见编辑:1、编辑:2和编辑:3,我添加了stacktrace,其中包含触发异常的部分代码。汉诺瓦纳很可能是部分正确的。除非JavaFX.application.application实例已经初始化(由JavaFX初始化,而不是由您初始化),否则JavaFX将无法工作。您可能需要从在
之前用
@注释的方法调用。如果发生了未初始化的异常工具包,为什么它不在MacOS或Linux中发生?可能取决于MacOS、Linux或Windows上使用的JRE版本。什么是异常的“抑制发生”?是什么让您相信这是未初始化JavaFX应用程序的症状?我在链接的SO问题中没有看到提到问题堆栈跟踪中的任何类。无法生成一个最小的完整示例,因为存在许多依赖项,您对在静态初始化器求值期间发生异常这一事实的认识是正确的,请参阅上面我的编辑
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); }
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)