2 Attachment(s)
Cannot compile "Hello World"; Cannot find or load main class
Hello, I am new to Java...so new, in fact, than I can't even get "Hello World" to run.
At first, when I tried to run the class file, the console window flashed, so I wrote a batch file that would compile the .java file and a separate one that would run the .class file. This sort of worked. It ran, and the console screen didn't close immediately. However, I'm getting a very annoying error message now:
Attachment 1975
compile.bat:
Code:
javac HelloWorld.java
pause
run.bat:
Code:
java HelloWorld.class
pause
HelloWorld.java:
Code:
public class HelloWorld{
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Attachment 1974
I have already done a google search, but the only thing I can find on it is about .jar files. Can someone please help me?
Re: Cannot compile "Hello World"; Cannot find or load main class
I can't see why the following code causing errors.
I would reccomand using eclipse as a workspace, that would simplfy alot of things definitely if you are new to this language, Java IDE's
TIP: don't write that way, it's very confusin and unorginized.
Here are two common ways to do that:
Code:
public class HelloWorld{
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Code:
public class HelloWorld
{
public static void main(String[] args)
{
System.out.println("Hello World");
}
}
Most of the people code on the first exmaple style, but I prefer the second one.
It's up to you, just a tip :D