滨海做网站哪家好,做seo排名好的公司,国家公信网查询系统,域名邮箱怎么弄文章目录 创建过程javafx独立版报错 Exception in thread WindowsNativeRunloopThread java.lang.NoSuchMethodError: init javafx是java gui工具。 一般会转换为exe#xff0c;成为可交互的应用。 那么来个简单的例子吧。 先说明一点#xff0c;javafx不… 文章目录 创建过程javafx独立版报错 Exception in thread WindowsNativeRunloopThread java.lang.NoSuchMethodError: init javafx是java gui工具。 一般会转换为exe成为可交互的应用。 那么来个简单的例子吧。 先说明一点javafx不用任何依赖。用maven项目也可以。
创建过程
创建一个空pom.xml内容
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.3.11.RELEASE/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.example/groupIdartifactIdjavafx-demo/artifactIdversion0.0.1-SNAPSHOT/versionnamejavafx-demo/namedescriptionDemo project for Spring Boot/descriptionpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingmaven.compiler.source1.8/maven.compiler.sourcemaven.compiler.target1.8/maven.compiler.target/propertiesdependencies!-- poi --dependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml/artifactIdversion4.1.2/version/dependency!-- lang3 --dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactIdversion3.12.0/version/dependency!-- fastjson --dependencygroupIdcom.alibaba/groupIdartifactIdfastjson/artifactIdversion1.2.75/version/dependency!-- 工具类 --dependencygroupIdcn.hutool/groupIdartifactIdhutool-all/artifactIdversion5.8.14/version/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationfinalNamejavafx-demo/finalNameoutputDirectory../target/outputDirectoryforktrue/forkexecutabletrue/executable/configuration/plugin/plugins/build/project
创建类
public class Main extends Application {public static void main(String[] args) {launch(args);}public void start(Stage primaryStage) throws Exception {BorderPane root new BorderPane();Label label new Label(Hello World);root.setCenter(label);Scene scene new Scene(root);primaryStage.setScene(scene);primaryStage.setWidth(800);primaryStage.setHeight(600);primaryStage.setTitle(JavaFx Demo);primaryStage.show();}
}在该类右键运行弹框 hello world 表示成功。 然后打包再用exe4j转换为exe就可以供人使用了。
javafx独立版
java8是支持javafx的但是不太智能。java8之后javafx独立出来需要单独引入。
报错 Exception in thread “WindowsNativeRunloopThread” java.lang.NoSuchMethodError:
at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens详细报错 Exception in thread “WindowsNativeRunloopThread” java.lang.NoSuchMethodError: at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
这个报错可费了劲了。最终也没解决整理下做的尝试。 1、jdk版本不对JAVA_HOME设置为jdk11对应路径。 2、有说修改init方法的 覆盖类重写方法 com.sun.javafx.application.Application(报错了还没到改代码那层) 在init里面添加内容
if (osdetector.os windows) {
systemProperty java.library.path, D:\Program Files\Java\jdk-11.0.21
}
}3、发现jre不存在 bin\jlink.exe --module-path jmods --add-modules java.desktop --output jre
4、javafx maven插件添加内容(实测也无效) -Djava.library.pathD:\Program Files\Java\jdk-11.0.21
注网上有人说解决掉了是电脑只能安装一个jdk版本。个人电脑都是用的解压版应该只用切换java_home即可。卸载代价太大了还有很多其他项目。