Results 1 to 2 of 2
  1. #1
    falconfetus8 is offline Member
    Join Date
    Nov 2011
    Posts
    14
    Rep Power
    0

    Default 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:
    Cannot compile "Hello World"; Cannot find or load main class-console.png

    compile.bat:
    Java Code:
    javac HelloWorld.java
    pause
    run.bat:
    Java Code:
    java HelloWorld.class
    pause
    HelloWorld.java:
    Java Code:
    public class HelloWorld{
    public static void main(String[] args) {
    System.out.println("Hello World");
    }
    }

    Cannot compile "Hello World"; Cannot find or load main class-folderz.png

    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?

  2. #2
    tnrh1 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    251
    Rep Power
    4

    Default 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:
    Java Code:
    public class HelloWorld{
    	public static void main(String[] args) {
    		System.out.println("Hello World");
    	}
    }
    Java 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
    Last edited by tnrh1; 11-06-2011 at 01:29 AM.

Similar Threads

  1. "could not find or load main class"
    By questionortwo in forum New To Java
    Replies: 4
    Last Post: 09-30-2011, 03:27 AM
  2. Replies: 11
    Last Post: 08-18-2011, 11:54 PM
  3. Replies: 3
    Last Post: 08-25-2010, 11:21 AM
  4. Replies: 6
    Last Post: 05-18-2010, 06:11 PM
  5. Replies: 1
    Last Post: 06-30-2009, 03:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •