简体   繁体   中英

JavaFx in Eclipse on Mac OS

Hello I am working on a project for school. I am having a problem using JavaFX in eclipse on my mac. Had the problem in Catalina and now in Big Sur. I will post basic code below as it does not work with anything.

I get the following error:

Error: Could not find or load main class edu.unlv.mis768.labwork12.MyFirstGUI Caused by: java.lang.ClassNotFoundException: edu.unlv.mis768.labwork12.MyFirstGUI

Also when I Scroll over the import of JavaFX it says:

The import javafx cannot be resolved

And when I scroll over "Application" it says:

Application cannot be resolved to a type

I am uncertain as to what to do. I am considering just purchasing a windows laptop to use to complete this project.

Suggestions or help would be very much appreciated!!

Code below:

package edu.unlv.mis768.labwork12;

import javafx.application.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.stage.*;

@SuppressWarnings("restriction")

public class Basics extends Application {
    @Override /* Method in Application class */
    public void start(Stage primaryStage) {
        int sceneWidth = 100, sceneHeight = 150;
        
        Button button = new Button("Fear The Turtle");
        Scene scene = new Scene(button, sceneWidth, sceneHeight);
        primaryStage.setTitle("FX Button");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}

Looks like there is nothing wrong except (assuming you are using Java 9 or better) maybe you need to add a module-info.java Just pop it under the src or java dir and here is the one I used to get your project going

    module Labwork12 { 
requires javafx.fxml; 
requires javafx.controls; 
requires javafx.graphics; 
requires javafx.web; 
requires java.logging; 
requires java.desktop; 
opens edu.unlv.mis768.labwork12; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM