尽管存在于JDK中,但Java找不到JavaFx类 [英] Java cannot find JavaFx classes although present in JDK

查看:317
本文介绍了尽管存在于JDK中,但Java找不到JavaFx类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用javafx为其UI开发应用程序。我正在使用java 9.当我从github中继续开发我的新计算机并进行编译时,javafx类的所有引用都存在编译错误,只有javafx类。



<我在外部资源中搜索了jdk,而javafx包确实在它应该的位置。我还使用相同的jdk创建了一个新项目并打开了一个javafx窗口,该窗口工作正常。这告诉我这是一个项目特定的问题,而不是系统问题。



有没有人对此有所了解?谢谢。



编辑
我正在使用Intellij社区Ed。错误列表很宽泛,但这里有几个

解决方案

您的IDE可能已将项目设置为模块化Java 9项目。在模块化项目中,您可以指定项目所依赖的其他模块,以及模块中的哪些软件包应该公开给其他模块。关于模块的一个很好的一般教程是在 OpenJDK wiki 上。



如果类路径根目录中有 module-info.java 文件,则需要明确说明您的模块需要访问适当的JavaFX模块。添加

 需要javafx.controls; 

此文件:这样您就可以访问 javafx.controls 模块,以及它所依赖的模块( javafx.graphics javafx.base )。根据您的项目,您可能还需要

 需要javafx.fxml; 

和/或

 需要javafx.web; 

等。


I am currently working on an application using javafx for its UI. I am using java 9. When I pulled from github to continue development on my new computer and compiled, there were compilation errors at all references of javafx classes, and only javafx classes.

I searched in the jdk in external resources, and the javafx package was indeed where it was supposed to be. I also made a new project using the same jdk and opened a javafx window, which worked fine. This tells me that this is a project-specific issue, rather than a system issue.

Does anyone have some insight into this? Thanks.

EDIT I am using Intellij comunity Ed. The error list was expansive, but here are a few

解决方案

Your IDE may have set the project up as a "modular" Java 9 project. In modular projects, you specify which other modules the project depends on, and which packages in your module(s) should be exposed to other modules. A good general tutorial on modules is at the OpenJDK wiki.

If there's a module-info.java file in the classpath root, you need to explicitly state that your module requires access to the appropriate JavaFX modules. It may be enough just to add

requires javafx.controls ;

to this file: that will give you access to the javafx.controls module, and the modules on which it depends (javafx.graphics and javafx.base). Depending on your project, you may also need

requires javafx.fxml ;

and/or

requires javafx.web ;

etc.

这篇关于尽管存在于JDK中,但Java找不到JavaFx类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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