所以arrayLists對我來說是第一位的,據我所知,我一直在做正確的事,並遵循我的在線課程提供給我的例子。但是,出於某種原因或其他原因,我有一條紅線加下劃線......我會在簡短解釋這個程序後立刻得到結論。如何修復arrayList?
這個程序允許你輸入員工信息,按'list'按鈕(listButton)後輸出到employeeField等等。基本上總結了這個程序。
public class EmployeeView extends FrameView {
class Company { //this is the class to allow me to put 'company' in the arrayList...
String ID, firstName, lastName, annualSal, startDate, mileage;
Company (String _ID, String _firstName,String _lastName, String _annualSal, String _startDate) {
ID = _ID;
firstName = _firstName;
lastName = _lastName;
annualSal = _annualSal;
startDate = _startDate;
}
}
/** Define the ArrayList */
ArrayList <Company> inventory = new ArrayList <Company>();
private void AddActionPerformed(java.awt.event.ActionEvent evt) {
String c;
String ID, firstName, lastName, annualSal, startDate;
ID = IDField.getText(); //all this stuff grabs info from the Fields...which will then be stored in the array
firstName = firstNameField.getText();
lastName = lastNameField.getText();
annualSal = annualSalField.getText();
startDate = startDateField.getText();
下面兩行是罪魁禍首。我認爲「新」不是過時的,但它在那個例子中,所以我使用它......但是,當我擺脫它時,只有'公司'被加下劃線,第二行'c'是下劃線而不是整行劃線。無論如何,我希望這是有道理的...因爲它(從我所知道的)我唯一的問題。
c = new Company(ID, firstName, lastName, annualSal, startDate);
inventory.add(c);
}
private void ListActionPerformed(java.awt.event.ActionEvent evt) {
String temp="";
for (int x=0; x<=inventory.size()-1; x++) {
temp = temp + inventory.get(x).ID + " "
+ inventory.get(x).firstName + " "
+ inventory.get(x).lastName + " "
+ inventory.get(x).annualSal + " "
+ inventory.get(x).startDate + "\n";
}
employeeTArea.setText(temp);
}
你收到了什麼彙編錯誤? – Makoto 2013-05-01 18:22:54
您是否將鼠標懸停在下劃線上以查明錯誤是什麼?你有沒有試過編譯你的程序? – 2013-05-01 18:23:37
那裏好想......它說它已經定義好了,所以我剛剛刪除了第一個聲明和賓果!問題解決了。我不禁感到有點像一個白癡現在大聲笑,一切都好! – Que 2013-05-01 18:30:51