-3

因此,arrayLists 对我来说是第一个,据我所知,我所做的一切都是正确的,并遵循我的在线课程提供给我的示例。但是,由于某种原因或其他原因,我有一条红色下划线……我将在对该程序进行简要说明后立即了解。

该程序允许您输入员工信息,然后在按下“列表”按钮(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);


}
4

2 回答 2

5

你已经宣布cString; 您不能将 aCompany直接分配给 a String

将您的声明更改cCompany

于 2013-05-01T18:23:32.423 回答
0

c被声明为String上述。它应该是类型Company

于 2013-05-01T18:23:50.803 回答