【问题标题】:Eclipse- Source Not FoundEclipse-找不到源
【发布时间】:2015-06-22 09:55:20
【问题描述】:

我正在学习斯坦福 Java 课程(Java 的艺术和科学),致力于课程实现的 exciese。当我尝试运行下面的代码时,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;
}

【问题讨论】:

  • 你是如何运行你的代码的?您应该在问题中包含此问题。
  • 在 Eclipse 中。代码的前几行是; /* * 文件:员工。 java * ----------------------- * /import acm.program.; /** * 这个类代表一个简单的员工实现。 * 客户端可以使用 get 方法获取员工姓名和 * 主管姓名。 * 客户可以使用设置的方法更改员工的工资。 * */

标签: java eclipse


【解决方案1】:

通常您还需要一个包含 java 源代码文件的 zip 或 jar 文件。例如,如果您想查看 jre 的源代码,则需要 src.zip 之类的内容,并且需要将您的类指向该 zip 文件。

在你的情况下,我猜你需要 acm.src.zip 或 acm.src.jar 之类的东西。如果你找到它,你需要通过选择相应文件的正确位置将你的类指向这个 zip 或 jar 文件。

jar 文件类似于一个 zip 文件,它将所有 java 源文件(不是类)捆绑在一起。

【讨论】:

  • 我是 java 和 eclipse 的新手。在Project exploer窗口中,有acm.jar,Employee.java & Employee.class在它下面。然后我从教科书中复制源代码并运行另一个名为“Rational”的程序,它运行良好。
猜你喜欢
  • 2014-03-20
  • 2011-12-23
  • 2011-09-06
  • 2010-12-29
  • 2012-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多