当我将它输入Netbeans时,它工作了,我将应用程序显示在屏幕上,但我更喜欢使用eclipse,所以当我将其复制并粘贴到Eclipse中时,如果有人帮忙请不要工作。这是我没有编译的错误。
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
引起:java.lang.Error:未解决的编译问题: 访问限制:方法' Application.launch(String [])'不是API(对所需库的限制' C:\ Program Files \ Java \ jre1.8.0_51 \ lib \ ext \ jfxrt.jar')
at Tutorial1.main(Tutorial1.java:10)
... 11 more
异常运行应用程序Tutorial1
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
public class Tutorial1 extends Application {
public static void main(String[] args) {
launch(args);
}
Button btn;
@Override public void start(Stage primaryStage)
{
btn = new Button();
btn.setText("Click Me Please");
btn.setOnAction(e -> buttonClick());
BorderPane pane = new BorderPane();
pane.setCenter(btn);
Scene scene = new Scene(pane, 300, 250);
primaryStage.setScene(scene);
primaryStage.setTitle("The Click Me App");
primaryStage.show();
}
public void buttonClick()
{
if (btn.getText() == "Click Me Please")
{
btn.setText("You Clicked Me");
}
else
{
btn.setText("Click Me Please");
}
}
}
答案 0 :(得分:-1)
1 - 您不需要任何插件即可在Eclise中使用JavaFX。
2 - 当您创建新的“Java项目”时,Eclipse和Netbeans具有不同的文件夹结构。
致以最诚挚的问候,