当前位置: 技术问答>java相关
大家帮我看一下如下的JAVA代码错误出来哪里,为什麽同一个包里的类不能相互调用
来源: 互联网 发布时间:2017-04-18
本文导语: 程序1: HelloWorld.java package aaa; public class HelloWorld { public static void main(String arg[]) { Test a=new Test(); System.out.println("Hello World ,Hello World "); } } 程序2: Test.java package aaa; class Test { pub...
程序1:
HelloWorld.java
package aaa;
public class HelloWorld
{
public static void main(String arg[])
{
Test a=new Test();
System.out.println("Hello World ,Hello World ");
}
}
程序2:
Test.java
package aaa;
class Test
{
public void method()
{
System.out.println("Test,Test");
}
}
在DOS底下编译出现的错误如下:
G:code>javac HelloWorld.java
HelloWorld.java:6: cannot resolve symbol
symbol : class Test
location: class aaa.HelloWorld
Test a=new Test();
^
HelloWorld.java:6: cannot resolve symbol
symbol : class Test
location: class aaa.HelloWorld
Test a=new Test();
^
2 errors
HelloWorld.java
package aaa;
public class HelloWorld
{
public static void main(String arg[])
{
Test a=new Test();
System.out.println("Hello World ,Hello World ");
}
}
程序2:
Test.java
package aaa;
class Test
{
public void method()
{
System.out.println("Test,Test");
}
}
在DOS底下编译出现的错误如下:
G:code>javac HelloWorld.java
HelloWorld.java:6: cannot resolve symbol
symbol : class Test
location: class aaa.HelloWorld
Test a=new Test();
^
HelloWorld.java:6: cannot resolve symbol
symbol : class Test
location: class aaa.HelloWorld
Test a=new Test();
^
2 errors
|
在HelloWorld.java加上
import ClassPath.aaa.*;
ClassPath是你的环境变量classpath的某一个值
并且package要在的ClassPath目录下
试一下
import ClassPath.aaa.*;
ClassPath是你的环境变量classpath的某一个值
并且package要在的ClassPath目录下
试一下
|
CLASSPATH = .;D:j2sdk1.4.1_01lib;D:j2sdk1.4.1_01libtools.jar;D:j2sdk1.4.1_01libdt.jar;D:jboss-3.0.3_tomcat-4.1.12tomcat-4.1.xcommonlibservlet.jar;D:j2sdkee1.3.1libj2ee.jar;d:Program FilesMicrosoft SQL Server 2000 JDBClibmsbase.jar;d:Program FilesMicrosoft SQL Server 2000 JDBClibmssqlserver.jar;d:Program FilesMicrosoft SQL Server 2000 JDBClibmsutil.jar
JAVA_HOME = D:j2sdk1.4.1_01
PATH = I:oracleora92bin;C:Program FilesOraclejre1.3.1bin;C:Program FilesOraclejre1.1.8bin;d:Program FilesOraclejre1.3.1bin;d:Program FilesOraclejre1.1.8bin;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;D:PROGRA~1ULTRAE~1;D:j2sdk1.4.1_01bin;D:j2sdkee1.3.1bin;D:j2sdkee1.3.1lib;d:Sybaseshared;C:Program FilesMicrosoft SQL Server80ToolsBINN
JAVA_HOME = D:j2sdk1.4.1_01
PATH = I:oracleora92bin;C:Program FilesOraclejre1.3.1bin;C:Program FilesOraclejre1.1.8bin;d:Program FilesOraclejre1.3.1bin;d:Program FilesOraclejre1.1.8bin;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;D:PROGRA~1ULTRAE~1;D:j2sdk1.4.1_01bin;D:j2sdkee1.3.1bin;D:j2sdkee1.3.1lib;d:Sybaseshared;C:Program FilesMicrosoft SQL Server80ToolsBINN