我的程序有两个:(并且都在H:\java\cp5\中
classpath为H:\Program Files\j2sdk1.4.1_02\lib;.;H:\myjava\cp5)
// P.java
package cwen.tools;
public class P{
public static void rint(String s){
System.out.print(s);
}
public static void rintln(String s){
System.out.println(s);
}}
//// ToolTest.java
import cwen.tools.*;
public class ToolTest{
public static void main(String[]args){
P.rintln("rintln");
P.rint("rint");
} }
运行:H:\myjava\cp5>javac P.java -d .
H:\myjava\cp5>javac ToolTest.java
ToolTest.java:9: cannot access P
bad class file: .\P.java
file does not contain class P
Please remove or make sure it appears in the correct subdirectory of the classpath.
P.rintln("rintln");
^
1 error
\\---------------------------------------------
下面把//// ToolTest.java改一下为
//import cwen.tools.*;
public class ToolTest{
public static void main(String[]args){
cwen.tools.P.rintln("rintln");
cwen.tools.P.rint("rint");
} }
运行正确!请问这到底是怎么了啊?用import指定和在函数里写上绝对路径也有差别吗??
帮帮我啊.小生在线期待中——————
classpath为H:\Program Files\j2sdk1.4.1_02\lib;.;H:\myjava\cp5)
// P.java
package cwen.tools;
public class P{
public static void rint(String s){
System.out.print(s);
}
public static void rintln(String s){
System.out.println(s);
}}
//// ToolTest.java
import cwen.tools.*;
public class ToolTest{
public static void main(String[]args){
P.rintln("rintln");
P.rint("rint");
} }
运行:H:\myjava\cp5>javac P.java -d .
H:\myjava\cp5>javac ToolTest.java
ToolTest.java:9: cannot access P
bad class file: .\P.java
file does not contain class P
Please remove or make sure it appears in the correct subdirectory of the classpath.
P.rintln("rintln");
^
1 error
\\---------------------------------------------
下面把//// ToolTest.java改一下为
//import cwen.tools.*;
public class ToolTest{
public static void main(String[]args){
cwen.tools.P.rintln("rintln");
cwen.tools.P.rint("rint");
} }
运行正确!请问这到底是怎么了啊?用import指定和在函数里写上绝对路径也有差别吗??
帮帮我啊.小生在线期待中——————
set CLASSPATH=.;D:\PGM\Java\JavaMyEx;c:\j2sdk
然后再试下.
形式是因为你在当前目录运行的.当前目录有设路径.
而用import cwen.tools.*;就不行了--
还是不行啊,一样的错误
比如 你是D:\123\cwen 就添上D:\123
我前几天也出现过类似问题