Java无法找到我的主类

时间:2014-10-24 06:18:45

标签: java windows

好的,首先,对任何类型的编程都是全新的。我正在尝试http://www.wikihow.com/Write-Your-First-Program-in-Java。我跟着它到T但是在命令提示符下每次输入“java HelloWorld”时它都会出现“错误:无法找到或加载主类HelloWorld。为什么会这样?

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World.");
    }
}

是的,我编译了它,有一个HelloWorld.java和.class

    Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\BrianC>dir
 Volume in drive C is Acer
 Volume Serial Number is 08EF-47A2

 Directory of C:\Users\BrianC

10/22/2014  05:59 PM    <DIR>          .
10/22/2014  05:59 PM    <DIR>          ..
10/19/2014  01:20 PM                83 .atl.properties
12/15/2013  05:40 PM    <DIR>          Contacts
10/24/2014  01:24 AM    <DIR>          Desktop
10/14/2014  06:27 PM    <DIR>          Documents
10/24/2014  12:15 AM    <DIR>          Downloads
08/10/2014  08:13 AM    <DIR>          Dropbox
01/16/2014  07:28 PM    <DIR>          Favorites
10/22/2014  06:35 PM    <DIR>          KAG-Beta
07/15/2014  03:13 PM    <DIR>          Links
12/15/2013  05:40 PM    <DIR>          Music
10/03/2014  09:49 AM    <DIR>          Pictures
04/09/2014  11:37 AM    <DIR>          Saved Games
12/15/2013  05:40 PM    <DIR>          Searches
12/15/2013  05:40 PM    <DIR>          Videos
               1 File(s)             83 bytes
              15 Dir(s)  325,924,110,336 bytes free

C:\Users\BrianC>java HelloWorld
Error: Could not find or load main class HelloWorld

C:\Users\BrianC>

1 个答案:

答案 0 :(得分:1)

正如评论中提到的@frankfg,我不会在此发布所有细节,但这应该足够了:

C:\TEMP>dir Hell*
 Volume in drive C is YYY
 Volume Serial Number is XXX

 Directory of C:\TEMP

24/10/2014  12:13               426 HelloWorld.class
24/10/2014  12:13               126 HelloWorld.java
               2 File(s)            552 bytes
               0 Dir(s)  140,363,472,896 bytes free



C:\TEMP>java HelloWorld
Error: Could not find or load main class HelloWorld

C:\TEMP>java -cp . HelloWorld
Hello World.