Main.java 中有class没有找到.注意大小写的问题

解决方案 »

  1.   

    java.lang是一个特殊的类库,她会自动导入每个Java File.在此我提供给你一个简单的
    Hello World例程,看是否和你的一样.
    附:
    //:HelloWorld.java
    import java.util.*;
    public class HelloWorld
    {
        public static void main(String[] args) {
            String pzzStr1;
            String pzzStr2;
            String pzzStr3;
            pzzStr1 = args[0];
            pzzStr2 = args[1];
            pzzStr3 = args[2];
            System.out.println("Hello world!");
            System.out.println(pzzStr1 + " " + pzzStr2 + " " + pzzStr3);
        }
    }///:~
      

  2.   

    HelloWorld.java 如下:
    import java.io.*;public class HelloWorld{
      public static void main(String args[]){
         System.out.println("Hello World");
      }
    }Main.java 如下:/*
    // START array
    // Implementation of String.getChars().
    public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) {
        System.arraycopy(value, offset + srcBegin, dst, dstBegin, 
            srcEnd - srcBegin);
    }
    // END array
    */import java.util.Date;
    import java.util.Properties;
    import java.util.Enumeration;
    import java.io.*;class Main {
    // START err
    public static void usage() {
        System.err.println("Usage: testprog <username> <age>");
        System.exit(-1);
    }
    // END err// START in
    // reads a line from standard input
    public static String getLine() {
        StringBuffer buf = new StringBuffer(80);
        int c;
        try {
            while ((c = System.in.read()) != -1) {
                char ch = (char) c;
                if (ch == '\n')
                    break;
                buf.append(ch);
            }
        } catch (IOException e) {
            System.err.println(e);
        }
        return (buf.toString());
    }
    // END inpublic static void setIO() {
        try {
    // START setIO
    System.setIn(new java.io.FileInputStream("myinputfile"));
    System.setOut(new PrintStream(new java.io.FileOutputStream("myoutputfile")));
    System.setErr(new PrintStream(new java.io.FileOutputStream("myerrinputfile")));System.out.println("Hello there file"); // using new out
    System.err.println("Hello there err file");     // using new err
    // END setIO} catch (java.io.IOException e) {
        e.printStackTrace();
    }
    }public static void main(String[] args) {
    // START date
    // Create a Date object using today's date
    Date today = new Date(System.currentTimeMillis());
    System.out.println("Today: " + today.toString());
    // END date
    {
    // START getprops
    Properties props = System.getProperties(); // get list of properties
    // Print properties using Enumeration
    for (Enumeration enum = props.propertyNames(); enum.hasMoreElements();) {
        String key = (String)enum.nextElement();
        System.out.println(key + " = " + (String)(props.get(key)));
    }
    // END getprops
    setIO();
    }
    {
    // START getprop
    // get user's home directory
    String homeDir = System.getProperty("user.home");
    // If 'outDir' not found, use 'homeDir' as default
    String outDir = System.getProperty("testdir", homeDir);
    // END getprop
    System.out.println("homeDir: " + homeDir);
    System.out.println("outDir: " + outDir);
    }
    /*
    // START getsec
    // Implementation of Thread.checkAccess()
    public final void checkAccess() {
        SecurityManager security = System.getSecurityManager();
        if (security != null) {
            security.checkAccess(this);
        }
    }
    // END getsec
    */
    {
    String s1 = getLine();
    System.out.println("in: " + s1);
    }
    {
    // START setprops
    Properties props = System.getProperties();
    // Add 'outDir' property
    props.put("outDir", "/tmp");
    // overwrites System properties with new properties
    System.setProperties(props);
    // END setprops
    System.out.println("outDir: " + System.getProperty("outDir"));
    }usage();
    }
    }
      

  3.   

    我把你的HelloWorld存成HelloWorld.java
    javac HelloWorld.java通过
    java HelloWorld
    还是该例外
      

  4.   

    建议你这样
    public class Main{
    }
    我的JDK1.1.7是可以执行你上面的Main的。
    编译,执行都没有问题。
      

  5.   

    我现在觉得可能jdk1.2.2装的有问题
      

  6.   

    十之八九是classpath的問題,你的文件是否在classpath中包括的路徑里?
      

  7.   

    谢谢你,success!!
    不是将$JavaHome\bin和$JavaHome\jre\lib\rt.jar加入classpath就行吗?
    为何*.class也需要,请详述
      

  8.   

    $JavaHome\bin和$JavaHome\jre\lib\rt.jar
    只是JDK提供的标准库,
    你要运行自己的程序,当然要自己的*.class包含到CLASSPATH中才可以。
    以后自己的class多了,可以用jar命令作成package(*.jar),然后把此*.jar文件放到你的CLASSPATH中。
      

  9.   

    我知道了,一定是你的classpath里没有当前目录!
    呵呵,加一个 “.\;" in your classpath.
      

  10.   

    i agree with people above ,sorry i can't input chinese now