使用Java SE 8u25在Eclipse中无法解析某些javafx类 [英] Some javafx classes cannot be resolved in Eclipse using Java SE 8u25

查看:1001
本文介绍了使用Java SE 8u25在Eclipse中无法解析某些javafx类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我使用的是Win7 64位,Eclipse Helios, jre在类路径中,如下所示:



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



Eclipse显示我尝试使用 javafx.scene.control.Button时,javafx.scene.control.Control类型无法解析,并从所需的.class文件间接引用。的setText(字符串)
尝试创建一个 StackPane 对象时,会出现类似的问题。



以下是到目前为止的代码:

  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异常{

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

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

});

StackPane root = new StackPane();

}
}

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

解决方案

注意:我看到您正在使用Eclipse Helios。您还可以下载最新版本的Eclipse Luna。这样做也可以。






您可以尝试 e(fx)剪辑,这可能是使用Eclipse开发FX应用程序时有用的IDE扩展。要执行此操作,请按照以下步骤操作:


  1. 打开Eclipse并转到帮助>安装新软件,然后插入URL http://download.eclipse.org/efxclipse/updates-released/1.1.0/site/ 使用:,然后按Enter键

  2. 加载软件包后,选择并安装它们

  3. 重新启动Eclipse后,您可以转到文件>新>其他... 并选择 JavaFX> JavaFX项目

  4. 还有一个步骤:将 jfxrt.jar 添加到类路径中转到项目属性并选择添加外部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. 准备制作可爱的JavaFX GUI!



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


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

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

I'm trying to replicate the code from this tutorial: 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 StackPane object.

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.

解决方案

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


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

  1. Open Eclipse and go to Help > Install New Software and 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.jar to 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!

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

这篇关于使用Java SE 8u25在Eclipse中无法解析某些javafx类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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