程序1:
package abc;
public class Client{
public static void main(String[] args){
Server ser = new Server();
System.out.println(ser.PI+ser.sayHello);
System.exit(0);

}
}
程序2:package abc;
public class Server{
final double PI = 3.1415926;
public static void sayHello(){
System.out.println("hello baby");
}
}
想实现通过程序1调用程序2里的方法 打印出"hello baby" 和PI的值我先 F:\java>javac -d ke ke/Server.java
再   F:\java>javac -d ke ke/Client.java
编译第一个没问题 
到了第二个就出错了
F:\java>javac -d ke ke/Client.java
ke/Client.java:4: 找不到符号
符号: 类 Server
位置: 类 abc.Client
                Server ser = new Server();
                ^
ke/Client.java:4: 找不到符号
符号: 类 Server
位置: 类 abc.Client
                Server ser = new Server();
                                 ^
2 错误我的CLASSPATH  : .;F:\java\ke\abc;

解决方案 »

  1.   

    没搞懂你想要表达一个什么意思....
    你有没有按照包名把class放在相应的目录下?
      

  2.   

    有点乱。1, your package name is "abc". If I am not wrong, your "abc" directory is under directory "ke". You should put your two .java source files under directory "abc".2, When you want to compile, you'd better execute javac in directory "ke".
        F:\java\ke\javac abc\*.java3, You will see the compiled .class files in directory "abc".4, F:\java\ke\java abc.Server or F:\java\ke\java abc.Client to execute programs.5, Your class path should be .;F:\java\ke (without "abc", becaue "abc" is a package name).6, What the hell do you need to specify a CLASSPATH varialbe? I have been using Java for 7 years, but I have never created a CLASSPATH System Variable. Specifying a System CLASSPATH variable may create confusing problems when you have many java programs on the same system. If a CLASSPATH variable is really necessary for an application, I'd use a batch (.bat) file to set the CLASSPATH variable for this application only. Other Java applications will not be affected.
      

  3.   

    为什么要在dos下运行,用IDE多好
      

  4.   

    IDE不会用啊…… 刚开始学……
      我先试试 z_lping(Schemer)的方法  都是英文 …… 得看会……
      

  5.   

    to Clayz(): Server能生成class  而且在 abc下
     Client 不能编译  没法生成class……
      

  6.   

    to z_lping(Schemer) 
    谢谢你打了那么多英文 ;)
    我把程序稍微改了一下   类之间的调用应该没问题
    2个.class能生成  但是输入以下命令的时候  又出错了……
    F:\java\ke>java abc.Client
    Exception in thread "main" java.lang.NoClassDefFoundError: abc/Client就这点问题弄一天了都 基本明白了package干什么用 和怎么用了
    可还是出错…… 茫然了
      

  7.   

    那是因为你的CLASSPATH在搞怪吧,把它删了。或者你可以这样:java -cp . abc.Client试试看。