-2

I'm having a issue where no matter what compiler I use, it builds the program but errors out with:

Error: Could not find or load main class com.company.Main Caused by: java.lang.ClassNotFoundException: com.company.Main Process finished with exit code 1

I was told its my CPU can't cope with java, anyone got any solutions?

(P.S. I am using IntelliJ Community Edition.)

java --version (cause someone asked) Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

P.S: I am running Windows 11 64bit on a Intel Core i5 6200u on 12gb of RAM.

Kevon
  • 7
  • 1
  • 4
    On your terminal, run the following command -- `java --version`. Then, edit your question to include it. And Java is very portable, so I am 99% sure that it is not a problem with Java or your CPU. Likely something is in the wrong folder – davidalayachew May 30 '22 at 18:49
  • 1
    also, please specify what operating system you are using (such as, say, Windows 10 64 bit), and what hardware you have below (say, an Intel i5 CPU) – tucuxi May 30 '22 at 18:51
  • 2
    Does this answer your question? [How do I resolve ClassNotFoundException?](https://stackoverflow.com/questions/17408769/how-do-i-resolve-classnotfoundexception) – QBrute May 30 '22 at 18:52
  • 1
    It would help if you showed your code. A simple `Hello World` would suffice. – WJS May 30 '22 at 19:01
  • Also [edit] your question to include the directory structure you have of your java file(s), in which directory you are in your terminal, how you compile your java file(s) and how exactly you try to start your application. – Progman May 30 '22 at 19:12
  • *I was told ...* - you were told wrong. The problem is something about how you're running Java, – dangling else May 30 '22 at 19:18
  • 1
    Just run `java -version` only one dash. – matt May 30 '22 at 19:32
  • `java --version` (two dashes) may work for later versions of Java (such as OpenJDK v17); but `java -version` (one dash) is more useful here, since it will also work with earlier versions (such as Java v8). – andrewJames May 30 '22 at 20:09

1 Answers1

-1

If you are compiling/running a single Java file with the Main class, run the following commands to compile and run your java code.

Compile:

javac MyApp.java

Run:

java MyApp

If you are using any tools like Maven or created your project using an IDE like NetBeans, Intellij IDEA or Eclipse, please edit and mention that in your question.

Isuru Perera
  • 101
  • 6
  • Ok so I editied my question with the compiler and the java version.. – Kevon May 30 '22 at 19:19
  • The error message they receive shows their class is in a package. *If* you want to compile and run it, you can use `-d` so that the directories are correctly created.I suspect they're doing what you say and are not in the correct folder for the class path. – matt May 30 '22 at 19:31
  • In IntelliJ IDEA, you can browse to the Java Main Class and there will be an option to directly run the Main method. First, try to run your program like that and make sure it will run without any issue. – Isuru Perera May 30 '22 at 19:47