Error need help After I compiled my program on command prompt I tried to run the program but it did not work It said "Error could not find or load main class" Could someone plz tell me what to put as my path classpath and javahome Thanks in advance. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Error need help After I compiled my program on command prompt I tried to run the program but it did not work It said "Error could not find or load main class" Could someone plz tell me what to put as my path classpath and javahome Thanks in advance.

7th Sep 2016, 10:41 PM
Chuckinator
16 Answers
+ 2
so you ran javac on 'myclass.java' which produced 'myclass.class', you should just need to run 'java myclass' path needs to be set in your system environment to include the path to the jdk binary directory, but if you've managed to run javac, then it seems like it's already there. classpath only really matters if you're pulling classes from other locations and you shouldn't need to worry about javahome unless you're building an application that requires exec of java, which you don't need seeing as you're running java from console.
7th Sep 2016, 10:57 PM
Greg Sims
Greg Sims - avatar
0
Really? I never experienced that.
7th Sep 2016, 11:14 PM
violet
0
so what is the exact thing i need to put in the path
7th Sep 2016, 11:16 PM
Chuckinator
0
Assuming you're on windows, you should append something like ";C:Program Files/Java/jdkx.xx/bin" but when adding the file path, find the folder which contains javac and use the path to that.
7th Sep 2016, 11:41 PM
Greg Sims
Greg Sims - avatar
0
Sorry O dont get the second part you said the part about adding the file path Can you rexplain that.
7th Sep 2016, 11:49 PM
Chuckinator
0
did you run javac from console just by typing it? if so then you don't need to change the path
8th Sep 2016, 12:04 AM
Greg Sims
Greg Sims - avatar
0
What do u mean by run javac by console
8th Sep 2016, 12:07 AM
Chuckinator
0
you said you compiled your program. you compile with javac
8th Sep 2016, 12:09 AM
Greg Sims
Greg Sims - avatar
0
Yes in command prompt I wrote javac xxx.java and it compiled but I cant get it to run
8th Sep 2016, 12:11 AM
Chuckinator
0
just type "java xxx" without the .class extension. make sure your cmd is in the same directory as the file
8th Sep 2016, 12:13 AM
Greg Sims
Greg Sims - avatar
0
I have but it says Error : Could not find or load main class could u also just give me whatyou have as your classpath and java home anyway
8th Sep 2016, 12:15 AM
Chuckinator
0
are you sure you have your main function written correctly? should be "public static void main (String[] args){ ..."
8th Sep 2016, 12:17 AM
Greg Sims
Greg Sims - avatar
0
yes I have public static void main(String [] args) {
8th Sep 2016, 12:21 AM
Chuckinator
0
so can u plz give me your classpath and javahome becuz when i type javac -version in cmd it says it is not recognized as an internal or external command , operable program or batchfile
8th Sep 2016, 12:33 AM
Chuckinator
0
are you sure that you have put main function inside a class?
8th Sep 2016, 2:00 AM
Tiger
Tiger - avatar
0
Yes but thank you i found it online i had to put java -classpath C:\Xxx package.class
8th Sep 2016, 2:03 AM
Chuckinator