2015-06-22 109 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