java.lang.NoClassDefFoundError:com/sun/javafx/css/converters/SizeConverter [英] java.lang.NoClassDefFoundError: com/sun/javafx/css/converters/SizeConverter

查看:72
本文介绍了java.lang.NoClassDefFoundError:com/sun/javafx/css/converters/SizeConverter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在SceneBuilder中创建JavaFX应用.

I'm creating a JavaFX app in scenebuilder.

我的FXML包含自定义胶子JavaFX对象.

My FXML contains custom gluon JavaFX objects.

我正在使用他们的"AppBar"和"Icon"对象.

I'm using their 'AppBar' and 'Icon' objects.

在加载fxml文件时,出现"java.lang.NoClassDefFoundError:com/sun/javafx/css/converters/SizeConverter"错误.

When loading in the fxml file, I get a 'java.lang.NoClassDefFoundError: com/sun/javafx/css/converters/SizeConverter' error.

完整跟踪:

 Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com/sun/javafx/css/converters/SizeConverter
        at com.gluonhq.charm.glisten.control.AppBar.<clinit>(SourceFile:409)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
        at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
        at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
        at java.base/java.lang.Class.newInstance(Class.java:591)
        at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1019)
        at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:754)
        at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
        at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
        at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
        at src.main.java.MainScreen.profileClick(MainScreen.java:107)
        at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        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.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:49)
        at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
        at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8890)
        at javafx.controls/javafx.scene.control.Button.fire(Button.java:203)
        at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:206)
        at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
        at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
        at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
        at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
        at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
        at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        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.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$MouseHandler.process(Scene.java:3862)
        at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1849)
        at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2590)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
        at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
        at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
        at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
        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)
Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.converters.SizeConverter
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 60 more

我检查了过去类似类型的问题,但是他们推荐的唯一解决方案是降级到Java8-这是一个Java13项目.

I have checked past questions of a similar type, however the only solution they recommend is downgrading to Java8 - this is a Java13 project.

引用接受的回复:

在Java 9中,以前的内部类

In Java 9, the previous internal class

com.sun.javafx.css.converters.PaintConverter公开为

com.sun.javafx.css.converters.PaintConverter became public as

javafx.graphics模块中的javafx.css.converter.PaintConverter.

javafx.css.converter.PaintConverter in the module javafx.graphics.

从此方法调用加载:

private void profileClick( ActionEvent event) {
                clearScreen();

                Profile prof = new Profile();
                ProfileController profController = new ProfileController(prof);

                try{
                mainPane.setCenter(profController.getLoader().load());
              }
                catch(Exception e){
                  System.out.println(e);
                }

            }

"getLoader"在其中检索具有正确目录的FXML加载器.

Where 'getLoader' retrieves an FXML loader with the correct directory.

我的gradle.build文件如下:

My gradle.build file is as follows:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

dependencies {
    testCompile 'junit:junit:4.12'
    testCompile 'org.testfx:testfx-junit:4.0.15-alpha'
    testCompile 'org.hamcrest:hamcrest-all:1.3'
      compile "com.opencsv:opencsv:4.0"
    compile 'com.gluonhq:charm:5.0.0'
}

repositories {
  jcenter()
  maven {
       url 'http://nexus.gluonhq.com/nexus/content/repositories/releases/'
   }
   mavenCentral()
   }

javafx {
    version = "13"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

mainClassName = "src.main.java.MainScreen"

如何解决此错误?

推荐答案

鉴于JavaFX在8至9+之间的主要API更改(其中,外观和CSS解析器已公开),任何在JavaFX 13上运行的项目不能使用为Java 8创建的依赖项.

Given the major API changes in JavaFX between 8 and 9+ (among others, the skins and css parsers were made public), any project that runs on JavaFX 13 can't use dependencies created for Java 8.

2018年发布的Gluon Mobile 5( com.gluonhq:charm:5.0.0 )可与Java 8配合使用,这说明了您遇到的异常.

Gluon Mobile 5 (com.gluonhq:charm:5.0.0), released in 2018, works with Java 8, and that explains the exception you get.

有一个针对Java 9编译的Gluon Mobile依赖项:

There is a Gluon Mobile dependency that was compiled for Java 9: 5.0.0-jdk9.

虽然可能会解决您的问题,但该版本不再更新.

While that will probably solve your issues, that version is not updated anymore.

最新版本是6.0.2,并且该版本是为JavaFX 11+创建的.

The latest release is 6.0.2, and this version was created for JavaFX 11+.

此版本也可用于GraalVM,并且使用客户端插件,可以创建所有平台(桌面/移动/嵌入式)的本地图像.

This version also works with GraalVM and, using the Client plugin, allows creating native images for all platforms (desktop/mobile/embedded).

您可以在此处看到一个有效的示例: HelloGluon .

You can see a working sample here: HelloGluon.

该示例在台式机上运行良好,但是Gluon Mobile库旨在在移动版(iOS/Android)上运行,并且具有商业许可证.

The sample runs fine on desktop, but the Gluon Mobile library is intended to work on mobile (iOS/Android), and it has a commercial license.

这篇关于java.lang.NoClassDefFoundError:com/sun/javafx/css/converters/SizeConverter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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