当我把它输入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: Unresolved compilation problem引起:访问限制:方法'Application.launch(String[])'不是API(限制所需库'C:Program FilesJavajre1.8.0_51libextjfxrt.jar')
at Tutorial1.main(Tutorial1.java:10)
... 11 more
应用程序异常运行教程1
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");
}
}
}
1 -在eclipse中使用JavaFX不需要任何插件。
2 - Eclipse和Netbeans有不同的文件夹结构,当你创建新的"Java项目"。
致以最诚挚的问候