1

我无法以编程方式创建新的 WebView。简单地调用new WebView()会导致以下异常:

java.lang.ExceptionInInitializerError
    at javafx.web/javafx.scene.web.WebEngine.<clinit>(WebEngine.java:339)
    at javafx.web/javafx.scene.web.WebView.<init>(WebView.java:260)
    // omitting unrelated stacktraces
    at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventFilterRecord.handleCapturingEvent(CompositeEventHandler.java:282)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchCapturingEvent(CompositeEventHandler.java:98)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:223)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchCapturingEvent(EventHandlerManager.java:180)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchCapturingEvent(CompositeEventDispatcher.java:43)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:52)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Scene$KeyHandler.process(Scene.java:4058)
    at javafx.graphics/javafx.scene.Scene$KeyHandler.access$1500(Scene.java:4004)
    at javafx.graphics/javafx.scene.Scene.processKeyEvent(Scene.java:2121)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:2595)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:217)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(GlassViewEventHandler.java:149)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$1(GlassViewEventHandler.java:248)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:390)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:247)
    at javafx.graphics/com.sun.glass.ui.View.handleKeyEvent(View.java:547)
    at javafx.graphics/com.sun.glass.ui.View.notifyKey(View.java:971)
    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:834)
Caused by: java.lang.UnsupportedOperationException: not implemented
    at javafx.base/com.sun.javafx.logging.PlatformLogger.getName(PlatformLogger.java:121)
    at javafx.web/com.sun.webkit.perf.PerfLogger.fullName(PerfLogger.java:155)
    at javafx.web/com.sun.webkit.perf.PerfLogger.registerProbe(PerfLogger.java:201)
    at javafx.web/com.sun.webkit.perf.PerfLogger.startCount(PerfLogger.java:227)
    at javafx.web/com.sun.webkit.perf.PerfLogger.<init>(PerfLogger.java:90)
    at javafx.web/com.sun.webkit.perf.PerfLogger.getLogger(PerfLogger.java:57)
    at javafx.web/com.sun.webkit.perf.PerfLogger.getLogger(PerfLogger.java:84)
    at javafx.web/com.sun.webkit.Invoker.<clinit>(Invoker.java:34)
    ... 37 more

它是一个错误吗?我正在使用 OpenJFX 11.0.1 和 OpenJDK 11.0.1。

4

1 回答 1

4

更新:

如评论中所述,此错误将在 OpenJFX 12 中修复。


这是来自的问题代码com.sun.javafx.logging.PlatformLogger

@Override
public String getName() {
   throw new UnsupportedOperationException("not implemented");
}

如您所见,它除了抛出观察到的异常外什么都不做。所有“已实现”的java.lang.System.Logger方法都是如此。

如果您按照您提供的堆栈跟踪所概述的代码进行操作,getName则最终会调用该方法,因为在初始化以及扩展类com.sun.webkit.perf.PerfLogger的过程中实例化了a。但是,仅在启用时调用。WebEnginecom.sun.webkit.InvokergetNamePerfLogger

粗略一看, aPerfLogger包裹了 a com.sun.javafx.logging.PlatformLogger,而它本身又包裹了 a System.Logger。如果在构造时返回 true,则PerfLogger启用。System.LoggerisLoggable(System.Logger.Level.FINE)PerfLogger

在这种情况下,此过程会导致创建System.Logger带有名称的 a "com.sun.webkit.perf.Locks"。这意味着UnsupportedOperationException如果您将其配置System.Logger为不记录任何内容Level.FINE或“更低”,则可以避免这种情况。这样做会使PerfLogger“禁用”,从而防止getName被调用。

注意:这是基于 OpenJFX 11.0.1 的源代码。提到的所有内容都是实现细节,可能会更改,恕不另行通知。

于 2018-12-24T05:54:40.150 回答