
SOLVED - Error: Could not find or load main class Main (FIXED 100%)
SOLVED - Error: Could not find or load main class Main (FIXED 100%)
could not find or load main class error in java vs code
java.lang.classnotfoundexception vscode
could not find or load main class error in java
main method not found in the file vscode
error could not find or load main class
Content
0.08 -> hello today we are going to solve this
problem that happens when you try to run your
6.8 -> java code in visual studio code
so let's see what is the problem
17.2 -> if you compile your code like this main.java it's
at the fully compiled but when you run the file
29.84 -> main then space error could not find or
load main class so the problem is it is java
39.28 -> who is not able to find your main class
so we have to do something about it
46.56 -> so the first problem could be you have not saved
your java file this would be the reason for this
55.04 -> error so to save your file you can go into file
menu and click on save or you can enable auto
62.96 -> save so that you don't have to always save
your port it will automatically save itself
68.48 -> now let's again run this code java main oh it
is still complaining us that class is not found
83.36 -> so no we have to first
compile the file and then main
91.76 -> main dot java
96.08 -> now you can see that a class file has been created
now let's try to run this classify java main
108.48 -> again it is showing an error could
not find or load the main class name
115.52 -> so this error is telling you that java is not
able to find your class file this class file
123.52 -> although it is in the same folder it is not able
to find it so we have to tell the class path
130.88 -> so to run this file we have to
write java dash class path and
139.6 -> dot main that's it you can see that hello world
is printed and this means that the class file is
150.72 -> present in the current directory this dot means
current directory but many times people prefer
157.76 -> to use this play button to run their code
you can see that if i use this play button
165.76 -> this is showing mirror why because
here compilation is done and after
171.04 -> compilation it is directly trying to execute
the main class so we have to change this stuff
177.36 -> so that it does not show us error so let's
do it go into settings and click on this icon
186.8 -> let's close this and this is your code runner
executor map this is how your code runner
194.16 -> extension is able to run your code it
basically throws this command into your
199.84 -> terminal so let's write this
thing over here java class path
208.56 -> and
212.08 -> done that's it
216 -> yeah and you are done now
let's go back and run your code
222.88 -> now you can see that hello world is printed even
when we are running it with the extension core
228.88 -> runner extension so that is how you solve the
problem and one more thing make sure your java
235.2 -> compiler and executor are properly properly
properly added in the environment variable
243.84 -> you can do that by going into the environment
variable settings and change it environment
251.2 -> variables and then you go into path and here
you can see this is the location of my java jdk
260.64 -> that's it so make sure you have this otherwise
your code will also not run so that's it
Source: https://www.youtube.com/watch?v=KLUaZa7VSt8