使用 Java SE 8u25 在 Eclipse 中无法解析某些 javafx 类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28011734/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 05:27:12  来源:igfitidea点击:

Some javafx classes cannot be resolved in Eclipse using Java SE 8u25

javaeclipsejavafx

提问by GeckStar

I installed the Java SE 8u25 JDK (64 Bit) from Oracle, which should include JavaFX.

我从 Oracle 安装了 Java SE 8u25 JDK(64 位),其中应该包含 JavaFX。

I'm using Win7 64 Bit, Eclipse Helios and included the jre in the classpath as shown here: enter image description here

我正在使用 Win7 64 位、Eclipse Helios 并将 jre 包含在类路径中,如下所示: 在此处输入图片说明

I'm trying to replicate the code from this tutorial: http://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm

我正在尝试复制本教程中的代码:http: //docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm

Eclipse shows me "The type javafx.scene.control.Control cannot be resolved. It is indirectly referenced from required .class files" when trying to use javafx.scene.control.Button.setText(String). A similar problem occurs when trying to create a StackPaneobject.

Eclipse 在尝试使用javafx.scene.control.Button.setText(String). 尝试创建StackPane对象时会出现类似的问题。

Here's the code so far:

这是到目前为止的代码:

package javaFX;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class HelloWorld extends Application {

@Override
public void start(Stage primaryStage) throws Exception {

    Button btn = new Button();
    btn.setText("Hello world!");
    btn.setOnAction(new EventHandler<ActionEvent>(){

        @Override
        public void handle(ActionEvent arg0) {
            System.out.println("Hello world!");
        }

    });

    StackPane root = new StackPane();

}
}

Tl;dr: Some JavaFX classes seem to be missing in Java SE 8u25 or I made a mistake in including the jre in the build path.

Tl; dr:Java SE 8u25 中似乎缺少某些 JavaFX 类,或者我在构建路径中包含 jre 时犯了一个错误。

采纳答案by mythbu

NOTE:I've seen that you are using Eclipse Helios. You could also download a latest version of Eclipse Luna. This will work also.

注意:我已经看到您正在使用 Eclipse Helios。您还可以下载最新版本的 Eclipse Luna。这也将起作用。



You could try e(fx)clipsewhich might be a useful IDE extension when developing FX apps with Eclipse. To do so follow these steps:

您可以尝试使用e(fx)clipse,这在使用 Eclipse 开发 FX 应用程序时可能是一个有用的 IDE 扩展。为此,请执行以下步骤:

  1. Open Eclipse and go to Help > Install New Softwareand insert the URL http://download.eclipse.org/efxclipse/updates-released/1.1.0/site/under "Work with:" and press enter
  2. Once the packages are loaded, select and install them both
  3. After a restart of Eclipse you can go to File > New > Other ...and select JavaFX > JavaFX Project
  4. There is one more step to do: add the jfxrt.jarto the classpath by going to the project properties and selecting "Add external JAR ..."
    • Windows: C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext
    • Mac OS: ./Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/jfxrt.jar.
  5. Ready to make cute JavaFX GUIs!
  1. 打开 Eclipse 并转到Help > Install New Softwarehttp://download.eclipse.org/efxclipse/updates-released/1.1.0/site/在“Work with:”下插入 URL ,然后按 Enter
  2. 加载包后,选择并安装它们
  3. 重新启动 Eclipse 后,您可以转到File > New > Other ...并选择JavaFX > JavaFX Project
  4. 还有一个步骤要做:jfxrt.jar通过转到项目属性并选择“添加外部 JAR ...”,将其添加到类路径中。
    • 视窗: C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext
    • Mac 操作系统:./Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/ext/jfxrt.jar.
  5. 准备好制作可爱的 JavaFX GUI!

Working example.

工作示例。

Notice: e(fx)clipse provides much more support for developing JavaFX applications. Feel free to take a look.

注意:e(fx)clipse 为开发 JavaFX 应用程序提供了更多支持。随意看看。

回答by Isthatso

EDIT:

编辑

You haven't import the class for StackPane :

您还没有为 StackPane 导入类:

import javafx.scene.layout.StackPane;

Previous answer :

上一个答案:

Basically you haven't import your javafx library , you can Add External JARs, and pointing out to jfxrt.jar, and it will work just fine.

基本上你还没有导入你的 javafx 库,你可以Add External JARs,并指出jfxrt.jar,它会工作得很好。

In my path , jfxrt.jaris in :

在我的路径中,jfxrt.jar在:

C:\Program Files\Java\jdk1.8.0_25\jre\lib\ext

There is a simple way,

有一个简单的方法,

回答by user2922935

Installing the latest JDK will help. Please see the two links: enter link description hereenter link description here

安装最新的 JDK 会有所帮助。请查看两个链接: 在此处输入链接描述 在此处输入链接描述