Error: Could not find or load main class HelloWorld
pls how do i solve this error on my java am new here and am also new to leaning java am a computer science i really need to lean it
this are errors i get
Code:
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\hp>cd desktop
C:\Users\hp\Desktop>cd java
C:\Users\hp\Desktop\java>cd student files
The system cannot find the path specified.
C:\Users\hp\Desktop\java>student files
'student' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\hp\Desktop\java>cd Student Files
The system cannot find the path specified.
C:\Users\hp\Desktop\java>cd StudentFiles
C:\Users\hp\Desktop\java\StudentFiles>cd Ch02
C:\Users\hp\Desktop\java\StudentFiles\Ch02>cd Hello
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>cd Greetings.java
The directory name is invalid.
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>greetings.java
Error: Could not find or load main class C:\Users\hp\Desktop\java\StudentFiles\C
h02\Hello\Greetings.java
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>java Greetings
Error: Could not find or load main class Greetings
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>java HelloWorld
Error: Could not find or load main class HelloWorld
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>
Re: Error: Could not find or load main class HelloWorld
I am not exactly sure what you are trying to do but to run command line prompts for your java program
1) get to directory of your .java files using cd
2) use javac nameOfProgram.java
this compiles it and creates a .class file
3) now use dir to see if the class file was created
4) now run java nameOfProgram
This should let you run your java program from command line
Re: Error: Could not find or load main class HelloWorld
Quote:
Originally Posted by
Cutejeff
... am also new to leaning java
So don't post beginner questions in the Advanced Java section. Moving the thread.
Also, don't use extra large fonts and all-bold sentences as that makes your post difficult to read. I've edited the post to make it more readable.
db
Re: Error: Could not find or load main class HelloWorld
Quote:
Originally Posted by
jhuber151
I am not exactly sure what you are trying to do but to run command line prompts for your java program
1) get to directory of your .java files using cd
2) use javac nameOfProgram.java
this compiles it and creates a .class file
3) now use dir to see if the class file was created
4) now run java nameOfProgram
This should let you run your java program from command line
pls i"ll love it if u can write the steps so i can follow it thanks for your help
Re: Error: Could not find or load main class HelloWorld
i tried again and got this error
c:\Program Files\javac>javac Greetings.java
Greetings.java:8: error: error while writing Greetings: Greetings.class (Access
is denied)
public class Greetings
^
1 error
Re: Error: Could not find or load main class HelloWorld
First learn to use your OS. Once you have that down, get back to thinking about Java. When you do, go through Trail: Getting Started (The Java™ Tutorials)
db
Re: Error: Could not find or load main class HelloWorld
Quote:
Originally Posted by
Cutejeff
i tried again and got this error
c:\Program Files\javac>javac Greetings.java
Greetings.java:8: error: error while writing Greetings: Greetings.class (Access
is denied)
public class Greetings
^
1 error
What I said. Recent Windows versions don't allow you to write files in the Program Files directory tree. Create a branch of your Documents tree for your Java apps.
db
Re: Error: Could not find or load main class HelloWorld
I am going to try with your code from before
Code:
C:\Users\hp>cd desktop
C:\Users\hp\Desktop>cd java
C:\Users\hp\Desktop\java>cd StudentFiles
C:\Users\hp\Desktop\java\StudentFiles>cd Ch02
C:\Users\hp\Desktop\java\StudentFiles\Ch02>cd Hello
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>//I AM ASSUMING THIS IS THE CLASS DIRECTORY WITH THE .JAVA FILE IN IT
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello> javac HelloWorld.java
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello> dir
//MAKE SURE IT CREATED A .CLASS FILE
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello> java HelloWorld
Re: Error: Could not find or load main class HelloWorld
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\hp>cd desktop
C:\Users\hp\Desktop>cd java\StudentFiles
C:\Users\hp\Desktop\java\StudentFiles>cd Cho2
The system cannot find the path specified.
C:\Users\hp\Desktop\java\StudentFiles>cd Ch02
C:\Users\hp\Desktop\java\StudentFiles\Ch02>cd Hello
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>j avac Greetings.va
error: Class names, 'Greetings.va', are only accepted if annotation processing i
s explicitly requested
1 error
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>j ava
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -no-jre-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions with specified granularity
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions with specified granularity
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
See Java SE Documentation at a Glance for m
ore details.
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>d ir
Volume in drive C has no label.
Volume Serial Number is E01E-0974
Directory of C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello
17/07/2012 01:45 <DIR> .
17/07/2012 01:45 <DIR> ..
12/10/2010 20:02 446 Greetings.java
12/10/2010 20:00 604 Greetings2.java
17/07/2012 06:32 186 HelloWorld.java
3 File(s) 1,236 bytes
2 Dir(s) 74,627,743,744 bytes free
C:\Users\hp\Desktop\java\StudentFiles\Ch02\Hello>
thats what i got
Re: Error: Could not find or load main class HelloWorld
how will i know if it has created a .class file?
Re: Error: Could not find or load main class HelloWorld
Hello i think i"ve got it let me try it again
Re: Error: Could not find or load main class HelloWorld
yes i've got it thanks to u all i really appreciate.
Re: Error: Could not find or load main class HelloWorld
... did your school not teach you how to use a command line? I have never taken classes, but I have taught a few and that is usually what I teach first. Maybe I am doing something wrong. :s:
Quote:
how will i know if it has created a .class file?
How do you know if you wrote a paper in Microsoft word and it saved as a .doc file. The answer, you check the folder you saved it in. Same with compiling. Check the folder you compiled in and there should be a file(s) with the name of the file you just compiled. Another way to know, is that javac will return without any errors. If you just get a new line in the command prompt, you will know something went really RIGHT :)-: , or REALLY, REALLY, WRONG! :(doh):
My suggestion before jumping into Java, as DarrylBurke, is to learn how to use your OS by learning how things work on your OS such as the command-line. Get so comfortable with it that you will use it for EVERYTHING. Try jumping into Linux and DO NOT INSTALL GUI. Get a good book that explains how to use the *nix command lines and learn from there. That is how I learned how to use a terminal.
Happy Learning!!