Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse error "Could not find or load main class"

I know there are many duplicates of this question, but I have looked at them all, and none of them have solved the issue.

I am trying to run a class that has a main function. I have cleaned the project, checked the classpath for '.', added the bin folder to the classpath under run configurations. I'm not sure what else to try because the class is certainly in the source folder.

Could someone please help me with this issue?

package testIt;

public class MemoryVisualizerApp extends Application{

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

//Setup the scene and launch with given properties
@Override
public void start(Stage primaryStage) throws IOException{
    Parent root = FXMLLoader.load(getClass().getResource("/MemoryVisualizer.fxml"));
    Scene scene = new Scene(root, 650, 300);
    //Set whether the screen should be re-sizable (possibly best size = default)
    primaryStage.setResizable(true);
    primaryStage.setMinHeight(300);
    primaryStage.setMinWidth(550);
    primaryStage.setTitle("Memory Usage");
    primaryStage.setScene(scene);
    scene.getStylesheets().add("testIt/MemoryVisualizer.css");
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() 
    {
        public void handle(WindowEvent e){
              /*Currently the threads continue running after window is closed. Looking for
              a way to stop the app threads when window closed without stopping the program.*/
        }
    });
    primaryStage.show();
    primaryStage.show();
}

}

This code is located within a package, withing the src folder. It utilizes some JavaFX files that arent shown but that shouldnt be an issue.

This is the error: Error: Could not find or load main class testIt.MemoryVisualizerApp

like image 751
G Boggs Avatar asked Sep 23 '14 19:09

G Boggs


Video Answer


1 Answers

If you are facing similar problem,it has to do with the "Run Configurations" not working properly in Eclipse.

error1

Please right clik on your java class containing the main method .Go to Run As-> Run Configurations and put the correct patrameters.Project should be the Project which contains the main class and Main class should be fuly qualified class name.See the snapshots below for clarity.It should wok fine then.Basically,you are creating a Run configuration and you can use that saved configuration for later use also.

selecting run configurationparameters to be entered correctly

like image 62
Kumar Abhinav Avatar answered Oct 26 '22 03:10

Kumar Abhinav