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.
16 odpowiedzi
+ 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.
0
Really? I never experienced that.
0
so what is the exact thing i need to put in the path
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.
0
Sorry O dont get the second part you said
the part about adding the file path
Can you rexplain that.
0
did you run javac from console just by typing it? if so then you don't need to change the path
0
What do u mean by run javac by console
0
you said you compiled your program. you compile with javac
0
Yes in command prompt I wrote javac xxx.java and it compiled but I cant get it to run
0
just type "java xxx" without the .class extension. make sure your cmd is in the same directory as the file
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
0
are you sure you have your main function written correctly? should be "public static void main (String[] args){ ..."
0
yes I have public static void main(String [] args) {
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
0
are you sure that you have put main function inside a class?
0
Yes
but
thank you i found it online
i had to put java -classpath C:\Xxx package.class