java Javafx 包不存在 IntelliJ
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43560833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javafx packegs do not Exist IntelliJ
提问by Luis Carlos Froes
I'm trying to code my first Javafx Application. But I keep getting an error even though my application is ok with the syntax. It's ok because I use the default one when initializing the first JavaFx application in IntelliJ . This here is my code:
我正在尝试编写我的第一个 Javafx 应用程序。但是,即使我的应用程序的语法没问题,我还是不断收到错误消息。没关系,因为我在 IntelliJ 中初始化第一个 JavaFx 应用程序时使用默认的。这是我的代码:
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I am using java 8 to run it. But when the application runs then this appears.
我正在使用 java 8 来运行它。但是当应用程序运行时,就会出现这种情况。
/home/jordan/IdeaProjects/new/src/sample/Main.java
Error:(3, 26) java: package javafx.application does not exist
Error:(3, 26) java: package javafx.application does not exist
Error:(7, 20) java: package javafx.stage does not exist
Error:(5, 20) java: package javafx.scene does not exist
And so on... And this also appears
等等……这也出现了
Information:javac 1.8.0_121 was used to compile java sources
回答by Turan Khan
I had the same problem which I solved this way:
我有同样的问题,我是这样解决的:
Go to File->Project Structureand then make sure "Project SDK" is "Java9"; also, "Project Language Level" should be java9. (More precisely it's called "9 Modules, private method in interfaces etc".)
转到File->Project Structure,然后确保“Project SDK”是“Java9”;另外,“项目语言级别”应该是java9。(更准确地说,它被称为“9 个模块,接口中的私有方法等”。)
The "project language level" downgrades your Java version. So you think you're using 9 but on the project you're not. This is why you have to change these settings.
“项目语言级别”会降级您的 Java 版本。所以你认为你正在使用 9 但在项目中你没有。这就是您必须更改这些设置的原因。
回答by shakespeare
Go to Tools
> Plugins
> and install updates
转到Tools
> Plugins
> 并安装更新