当前位置: 技术问答>java相关
刚刚入门java,一个小问题
来源: 互联网 发布时间:2015-11-05
本文导语: file: A.java public class A { public static void main(String[] args) { B b1=new B(); b1.print(); } } file:B.java public class B { public void print() { System.out.println("package test"); } } run: D:my>path PATH=d:j2sdk1.4bin D:my>java Usage: java...
file:
A.java
public class A
{
public static void main(String[] args)
{
B b1=new B();
b1.print();
}
}
file:B.java
public class B
{
public void print()
{
System.out.println("package test");
}
}
run:
D:my>path
PATH=d:j2sdk1.4bin
D:my>java
Usage: java [-options] class [args...]
(to execute a class)
or java -jar [-options] jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [
The default VM is client.
-cp -classpath javac A.java
A.java:5: cannot resolve symbol
symbol : class B
location: class A
B b1=new B();
^
A.java:5: cannot resolve symbol
symbol : class B
location: class A
B b1=new B();
^
2 errors
请问如何解决?
A.java
public class A
{
public static void main(String[] args)
{
B b1=new B();
b1.print();
}
}
file:B.java
public class B
{
public void print()
{
System.out.println("package test");
}
}
run:
D:my>path
PATH=d:j2sdk1.4bin
D:my>java
Usage: java [-options] class [args...]
(to execute a class)
or java -jar [-options] jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [
The default VM is client.
-cp -classpath javac A.java
A.java:5: cannot resolve symbol
symbol : class B
location: class A
B b1=new B();
^
A.java:5: cannot resolve symbol
symbol : class B
location: class A
B b1=new B();
^
2 errors
请问如何解决?
|
CLASSPATH
|
javac *.java
|
我试了,一点问题也没有,肯定是你的classpath 有问题
或者你根本就没有设classpath
或者你根本就没有设classpath
|
因为你在编译A.java时需要用到B.class,可是你还没有编译B.java
所以:
你先要运行
javac B.java
在运行
javac A.java
最后是
java A
所以:
你先要运行
javac B.java
在运行
javac A.java
最后是
java A
|
你还在dos下编译啊?!
可以下栽一个JCREATOR 呀
可以方便编译
可以下栽一个JCREATOR 呀
可以方便编译
|
to: fosdick_j(杰) ( )
好象不是这样吧~~你试试在没有B.class的时候能不能编译
好象不是这样吧~~你试试在没有B.class的时候能不能编译
|
你的CLASSPATH里是不是没有当前路径?
|
按照你的运行,一点问题都没有!!