在使用*导入语句时,JVM无法访问用户定义的类。
我的类路径为export CLASSPATH=.:/home/aksharaaaa/Documents/programs/core_java/class_java:
首先,我将Employee.java文件创建为一个包,即.
package com.durgasoft.core;
public class Employee
{
int eid;
String ename;
double esal;
public Employee(int eid1, String ename1, double esal1)
{
eid=eid1;
ename=ename1;
esal=esal1;
}
public void getEmployeeDetails()
{
System.out.println("Employee Details");
System.out.println("-------------------");
System.out.println("Eno:"+eid);
System.out.println("Ename:"+ename);
System.out.println("ESalary"+esal);
}
}
为了编译这个文件,我使用了以下命令'javac -d .. Employee.java',然后在class_java文件夹中创建了com/durgasoft/core/Employee.class文件。
然后我只在class_java文件夹中创建了test.java文件,并添加了以下代码。
import com.durgasoft.core.*;
public class test{
public static void main(String[] args){
Employee e= new Employee(111, "viay", 3333.333);
e.getEmployeeDetails();
}
}
当我编译test.java文件时,JVM会出现以下错误:
<b>test.java:5: error: constructor Employee in class Employee cannot be applied to given types;
Employee e= new Employee(111, "viay", 3333.333);
^
required: no arguments
found: int,String,double
reason: actual and formal argument lists differ in length
test.java:6: error: cannot find symbol
e.getEmployeeDetails();
^
symbol: method getEmployeeDetails()
location: variable e of type Employee 2 errors
如果我在test.java文件中使用全限定名,例如:import com.durgasoft.core.Employee;,那么JVM就能够编译和运行...
Employee
з±»зљ„жњєдјљпјџ - MarvinEmployee.class
文件并检查它是否包含预期的构造函数 - 注意查找类似于<init>^A^@^W(ILjava/lang/String;D)
的内容。 - Michael Lang