使用 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
Some javafx classes cannot be resolved in Eclipse using Java SE 8u25
提问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:
我正在使用 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 StackPane
object.
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 扩展。为此,请执行以下步骤:
- 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!
- 打开 Eclipse 并转到
Help > Install New Software
并http://download.eclipse.org/efxclipse/updates-released/1.1.0/site/
在“Work with:”下插入 URL ,然后按 Enter - 加载包后,选择并安装它们
- 重新启动 Eclipse 后,您可以转到
File > New > Other ...
并选择JavaFX > JavaFX Project
- 还有一个步骤要做:
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
.
- 视窗:
- 准备好制作可爱的 JavaFX GUI!
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.jar
is 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