我正在从事斯坦福Java课程(java的艺术和科学),致力于课堂实施的激励。当我尝试运行下面的代码时,Eclipse给出了错误:找不到源 - 源附件不包含Program.class文件的源。您可以通过单击下面的“更改附加源”来更改源附件。 我当前的位置是/ACMStarterProject/acm.jar
如果您知道如何解决此问题,请告诉我们。感谢。
public class Employee extends ConsoleProgram {
public void run() {
Employee emp = new Employee("John Smith", "Robert Cook", 78000);
println(emp.getName() + ", " + emp.getSupervisor() + ", " + emp.getSalary());
}
/**
* Creates a new employee object, which has name, supervisor’s name,
* and salary as its state.
* @param empName The name of the employee
* @param supName The name of the supervisor
* @param sal The salary of the employee
*/
public Employee(String empName, String supName, double sal) {
name = empName;
supervisor = supName;
salary = sal;
}
/**
* Returns the name of the employee.
* @return The name of the employee
*/
public String getName() {
return this.name;
}
/**
* Returns the name of the supervisor of the employee.
* @return The name of the supervisor of the employee
*/
public String getSupervisor() {
return this.supervisor;
}
/**
* Returns the salary of the employee.
* @return The salary of the employee
*/
public double getSalary() {
return this.salary;
}
/**
* Set the salary of the employee.
* @param sal The new salary of the employee
*/
public void setSalary(double sal) {
this.salary = sal;
}
/**
* Set the supervisor of the employee.
* @param supName The new salary of the employee
*/
public void setSupervisor(String supName) {
this.supervisor = supName;
}
/* Private instance variables */
private String name;
private String supervisor;
private double salary;
}
答案 0 :(得分:0)
通常你需要一个包含java源代码文件的zip或jar文件。例如,如果你想看到jre的源代码,你需要像src.zip这样的东西,你需要把你的类指向那个zip文件。
在你的情况下,我猜你需要像acm.src.zip或acm.src.jar这样的东西。如果你发现它,你需要通过选择相应文件的正确位置将你的类指向这个zip或jar文件。
jar文件类似于zip文件,它将所有java源文件(不是类)捆绑在一起。