使用Java SE 8u25在Eclipse中无法解析某些javafx类 [英] Some javafx classes cannot be resolved in Eclipse using Java SE 8u25
问题描述
我使用的是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扩展。要执行此操作,请按照以下步骤操作:
- 打开Eclipse并转到
帮助>安装新软件
,然后插入URLhttp://download.eclipse.org/efxclipse/updates-released/1.1.0/site/
使用:,然后按Enter键 - 加载软件包后,选择并安装它们
- 重新启动Eclipse后,您可以转到
文件>新>其他...
并选择JavaFX> JavaFX项目
- 还有一个步骤:将
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
。
- Windows:
- 准备制作可爱的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:
- Open Eclipse and go to
Help > Install New Software
and insert the URLhttp://download.eclipse.org/efxclipse/updates-released/1.1.0/site/
under "Work with:" and press enter - Once the packages are loaded, select and install them both
- After a restart of Eclipse you can go to
File > New > Other ...
and selectJavaFX > JavaFX Project
- 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
.
- Windows:
- 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屋!