2015-06-22 101 views
0

我正在做Stanford Java Class(java的艺术和科学),致力于实现class的exciese。当我尝试运行下面的代码时,Eclipse提供了错误:Source not found - 源附件不包含Program.class文件的源代码。您可以通过单击下面的更改附加源来更改源附件。 我的当前位置是/ACMStarterProject/acm.jarEclipse-未找到源

如果您知道如何解决此问题,请告诉我。谢谢。

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; 
} 
+2

你是如何运行你的代码?你应该包括这个问题。 Eclipse中的 –

+0

。代码中的前几行是;/* *文件:员工。 java * ----------------------- * */ import acm.program。*; /** *此类表示员工的简单实施。 *客户可以使用get方法获取员工姓名和主管姓名。 *客户可以使用设置的方法来更改员工的工资。 * */ – Jeff

回答

0

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

就你而言,我猜你需要类似acm.src.zip或acm.src.jar。如果您发现它,您需要通过选择相应文件的正确位置将您的课程指向此zip或jar文件。

该jar文件与将所有java源文件(不是class)捆绑在一起的zip文件类似。

+0

我是java和eclipse的新手。在项目探索器窗口中,有acm.jar,Employee.java&Employee.class在它下面。我从教科书中复制源代码并运行另一个名为“Rational”的程序,它运行正常。 – Jeff