问题
java version 1.8.0_221 eclipse version 2019-06 (4.12.0) I'm trying to make a basic JavaFX program. I've imported jfxrt external jar into the libraries tab under module build path.
I've been getting this error "Error: Could not find or load main class firstFX.eighthTry Caused by: java.lang.NoClassDefFoundError: javafx/application/Application"
The only advice I've found around the web tells me to get rid of any external jars, but I need jfxswt in order to use JavaFX. I've also tried to use Project > Clean, but that hasn't done anything either.
I'm at a loss, is there anything I can do to fix this? Code is below
package firstFX;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class eighthTry extends Application{
public static void main(String[] args) {
// TODO Auto-generated method stub
launch(args);
}
@Override
public void start(Stage arg0){
// TODO Auto-generated method stub
arg0.setTitle("Hello World!");
final Button btn = new Button();
btn.setText("Click Me!");
final StackPane root = new StackPane();
root.getChildren().add(btn);
arg0.setScene(new Scene(root, 300, 250));
arg0.show();
}
}
Edit: I've done a clean install of Eclipse (now 2019-09) and also installed e(fx)clipse via Help>Install new software then installing both things from http://download.eclipse.org/efxclipse/updates-released/3.3.0/site. I followed this tutorial.
For my code I added the JavaFX SDK under Properties> Java Build Path > Libraries>Module Path. I then put it at the top of the Order and Export tab.
Unfortunately, this hasn't changed anything. I still get the same error as I did above.
Additionally, I was mistaken about the name of the external jar I needed. I have since replaced the jfxswt.jar with jfxrt.jar. However, this has not fixed the error.
回答1:
Not sure how it looks but your class is missing package firstFX; is it in a folder called firstFX... ?
来源:https://stackoverflow.com/questions/58648826/could-not-find-or-load-main-class-while-trying-to-use-javafx-in-eclipse