0
class Simple{  
    public static void main(String [] args){  
         System.out.println("Hello Java");  
    }  
}

Running this program using command prompt:

javac Simple.java - compiled it successfully,
java Simple - shows error "Error: Could not find or load main class simple"

What are the reasons for showing this error?

I have set,

JAVA_HOME - C:\Program Files\Java\jdk1.8.0_241,
path- %JAVA_HOME%\bin,
CLASSPATH - C:\Program Files\Java\jdk1.8.0_241\bin

ernest_k
  • 44,416
  • 5
  • 53
  • 99
  • Does this answer your question? [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) – Binu Jan 25 '20 at 06:03
  • 1
    From the message "Error: Could not find or load main class **simple**" I suspect you are actually executing `java simple` instead of `java Simple` . Otherwise the message would have been "Error: Could not find or load main class **Simple**". These Java commands are **not** case insensitive. –  Jan 25 '20 at 06:07
  • No. i am using java Simple @EugenCovaci – Ajay Biswas Jan 25 '20 at 06:15
  • Check if the folder has any `simple` compiled class also. Delete all *.class files in the directory and run again – Rahul Agrawal Jan 25 '20 at 06:16
  • I read that post already, not helping me...@Binu – Ajay Biswas Jan 25 '20 at 06:17
  • I did that already @RahulAgrawal Now I found out that it works fine when I used notepad to write my code. But, why it shows an error when I used notepad++ to write the same code? – Ajay Biswas Jan 25 '20 at 06:17
  • Is this the whole file or does it contain other code also?? – Rahul Agrawal Jan 25 '20 at 06:19
  • whole file @RahulAgrawal – Ajay Biswas Jan 25 '20 at 06:21
  • show the results of 'dir' command on that directory – Rahul Agrawal Jan 25 '20 at 06:24
  • @RahulAgrawal Directory of C:\Users\CG-DTE\Desktop\NPTEL\Java\java program 25-01-2020 12.19 PM . 25-01-2020 12.19 PM .. 25-01-2020 12.19 PM 416 Simple.class 25-01-2020 12.18 PM 117 Simple.java 2 File(s) 533 bytes 2 Dir(s) 69,581,066,240 bytes free – Ajay Biswas Jan 25 '20 at 06:52
  • Shouldn't the evn. variable PATH be in caps?? Try 1. echo $PATH 2.) echo $JAVA_HOME – Rahul Agrawal Jan 25 '20 at 07:08
  • *"CLASSPATH - C:\Program Files\Java\jdk1.8.0_241\bin"* - That is incorrect. And possibly the cause of the problem. This is *explained* in the Q&A that Binu linked to. But unfortunately it is necessary to read the main answer (preferably *all of it*) to get the information you need. – Stephen C Jan 25 '20 at 08:00
  • For the record, setting CLASSPATH to that directory tells the `java` command to look only there for your ".class" files. Obviously, they are not there ... so Java says it cannot find them. You probably should set `CLASSPATH` to `.` in this case. Or better still unset it completely. – Stephen C Jan 25 '20 at 08:03

0 Answers0