0

I run my program from terminal, while it runs fine from IntelliJ. I get the error "could not find or load main class Main". It's not the filenames that is incorrect and neither does the file have any specified package name.

here is my Main.java file.

import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application{

    public static void main(String[] args){
        System.out.println("hej");
        launch();
    }

    @Override
    public void start(Stage stage){

    }

}

It seems to be something with javaFX. I am using linux

Pelle
  • 61
  • 1
  • 4
  • 1
    Did you compile it before launching it ? – Hearner Jul 19 '18 at 14:24
  • Change the signature of your `main(String args[])` to `main(String[] args)` – deHaar Jul 19 '18 at 14:25
  • I changed the signature from main(String args[]) to main(String[] args), still not working. It doesn't work if I try to run the IntelliJ productions files or compile it myself using javac command – Pelle Jul 19 '18 at 14:30
  • Does your class path and/or path environment variables point to where you Main.class file is located? Or are you trying to run it where it is located? – Erik Jul 19 '18 at 14:44
  • You don't need anything like as much code for a [mcve] (and you're also failing the "complete" part of that - perhaps missing some imports). A simple `main()` should be sufficient to demonstrate the problem. – Toby Speight Jul 19 '18 at 16:32
  • 1
    Possible duplicate of [What does "Could not find or load main class" mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – Octavia Togami Jul 19 '18 at 17:56
  • I am trying to run it from where it is located. Does it have something to do with that it is a JavaFX program? – Pelle Jul 20 '18 at 13:57
  • Please edit your post and copy-paste the command you use as well as the error you get (see [Why should I post complete errors?](https://meta.stackoverflow.com/questions/359146/why-should-i-post-complete-errors-why-isnt-the-message-itself-enough) for why transcribing the main point of the error message isn't as helpful as copy-pasting the full one) – that other guy Jul 20 '18 at 22:42

2 Answers2

0

These two tell the Java interpreter where the bytecode class files are. When you are getting the error: 'could not find or load main class', try them.

If your class file is saved in c:\folder directory with MyJavaFxApp program name

  1. java -cp c:\folder MyJavaFxApp
  2. java -cp . MyJavaFxApp
0

It was something to do with different versions of Java, I essentially changed the default version to a newer one using this guide

http://ask.xmodulo.com/change-default-java-version-linux.html

Thanks

Pelle
  • 61
  • 1
  • 4