Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 错误:无法解析为类型_Java_Eclipse - Fatal编程技术网

Java 错误:无法解析为类型

Java 错误:无法解析为类型,java,eclipse,Java,Eclipse,我在这一行得到这个错误: private List<Contractor> contractors = new ArrayList<Contractor>(); 通常这是一个重要的问题。如果您使用的是一个好的IDE(即Eclipse或Intellij),它将导入您需要的所有内容(如果您要求的话) 请参见我删除了/target文件夹中的所有内容,这对我很有用。你可以发布你的Contractor类吗?我没有看到你导入Contractor类…@Erik他也没有导入Custom

我在这一行得到这个错误:

private List<Contractor> contractors = new ArrayList<Contractor>();

通常这是一个重要的问题。如果您使用的是一个好的IDE(即Eclipse或Intellij),它将导入您需要的所有内容(如果您要求的话)


请参见

我删除了/target文件夹中的所有内容,这对我很有用。

你可以发布你的Contractor类吗?我没有看到你导入Contractor类…@Erik他也没有导入Customer。所以我认为它在同一个包中?粘贴代码时,请只发布其中有趣的部分,而不是全部(请先缩小问题的范围)。它很难阅读,而且不太可能有人会费心去阅读那么多的代码。这可能是一个可见性问题吗?该类似乎被定义为另一个类中的私有类?@user381091:我正在使用Eclipse。我插入了所需的导入,得到一个错误,上面写着:线程“main”java.lang中出现异常。错误:未解决的编译问题:代码中会有一些标记为红色的东西无法编译。你需要解决这个问题。如果导入没有编译,那么您的项目类路径是错误的。也就是说,您尝试导入的文件不在类路径上。导入时没有错误。错误出现在上述代码中的“承包商”一词处。
public class SwimCalc extends JFrame implements ActionListener {
    private JTabbedPane jtabbedPane; 
    private JPanel Customers;
    private JPanel Contractors; 
    private List<Customer> customers = new ArrayList<Customer>();

    // this fails
    private List<Contractor> contractors = new ArrayList<Contractor>();

    JTextArea NameTextCustomers, ExistTextCustomers, MessageTextCustomers, 
    NameTextContractors, ExistTextContractors, MessageTextContractors;
    JTextField lengthTextPool, widthTextPool, depthTextPool, volumeTextPool; 

    public SwimCalc() { 
        setTitle("Volume Calculator"); 
        setSize (300, 200); 

        JPanel topPanel = new JPanel(); 
        topPanel.setLayout( new BorderLayout() ); 
        getContentPane().add( topPanel ); 

        createCustomers(); 
        createContractors(); 

        jtabbedPane = new JTabbedPane(); 
        jtabbedPane.addTab("Customer", Customers); 
        topPanel.add(jtabbedPane, BorderLayout.CENTER); 
    }
}  
public JPanel createContractors(){ 
    Contractors = new JPanel(); 
    Contractors.setLayout(null); 

    NameTextContractors = new JTextArea("Select Add Contractor to Add Contractor." +
    "\nSelect Refresh to Refresh This Pane."); 
    NameTextContractors.setLineWrap(true); 
    NameTextContractors.setBounds(10, 10, 390, 150); 
    Contractors.add(NameTextContractors); 

    JButton Exit = new JButton("Exit"); 
    Exit.setBounds(30,170,80,20); 
    Exit.addActionListener(this); 
    Exit.setBackground(Color.white); 
    Contractors.add(Exit); 

    JButton AddContractors = new JButton("Add Contractor"); 
    AddContractors.setBounds(130,170,120,20); 
    AddContractors.setBackground(Color.white); 
    Contractors.add(AddContractors); 

    JButton Refresh = new JButton("Refresh"); 
    Refresh.setBounds(260,170,80,20); 
    Refresh.setBackground(Color.white); 
    Contractors.add(Refresh); 

    ExistTextContractors = new JTextArea("File Contractor.txt does not exist yet." +
    "\nIt will be created when you add Contractor."); 
    ExistTextContractors.setBounds(10, 200, 390, 60); 
    ExistTextContractors.setLineWrap(true); 
    Contractors.add(ExistTextContractors); 
    final JTextArea contArea = new JTextArea(6, 30); 
    final JTextArea ExistTextContractors; 

    ExistTextContractors = new JTextArea(2, 30); 
    ExistTextContractors.setLineWrap(true); 
    ExistTextContractors.setWrapStyleWord(true); 

    AddContractors.addActionListener(new ActionListener() 
{ 
public void actionPerformed(ActionEvent e){
    new Contractor("Contractor", SwimCalc.this); 

} 
});


Contractors.add(contArea); 
Contractors.add(AddContractors); 

Contractors.add(Refresh); 
Refresh.setMnemonic('R'); 

Refresh.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) 

{ 
NameTextContractors.setText ("");
try{
    File contOpen = new File("Contractor.txt"); 
    FileReader contAreaIn = new FileReader(contOpen); 
    contArea.read(contAreaIn, contOpen.getAbsolutePath()); 
    ExistTextContractors.setText("File exists and can be read."); 

} 
catch (IOException e3){ 
    ExistTextContractors.setText("The file could not be read." + e3.getMessage()); 
} 
} 
} 
);
return Contractors; 
} 
class Contractor extends JFrame 
{ 
private String[] states = {"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE",
        "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", 
        "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", 
        "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", 
        "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"}; 

private JComboBox StateList = new JComboBox(states); 
private JTextField NameText = new JTextField(25); 
private JTextField AddressText = new JTextField(25); 
private JTextField CityText = new JTextField(25); 
private JTextField ZipText = new JTextField(9); 
private JTextField PhoneText = new JTextField(10); 
private JTextField MessageTextContractors = new JTextField(30); 
private static final long serialVersionUID = 1L; 

private AddContButtonHandler addConHandler = new AddContButtonHandler();
private SwimCalc parent; 

public Contractor(String who, SwimCalc _parent) {
    popUpWindow (who); 
    parent = _parent; 
}

public void popUpWindow(final String who) {
    final JFrame popWindow; 
    popWindow = new JFrame(who); 
    popWindow.setSize(425, 350); 
    popWindow.setLocation(100, 100); 
    popWindow.setVisible(true); 
    setDefaultCloseOperation(EXIT_ON_CLOSE); 

    Container c = new Container(); 

    popWindow.add(c); 

    c.setLayout(new FlowLayout()); 

    JPanel one = new JPanel(); 
    JPanel two = new JPanel(); 
    JPanel three = new JPanel(); 
    JPanel four = new JPanel(); 
    JPanel five = new JPanel(); 
    JPanel six = new JPanel(); 

    one.add(new JLabel(who + " Name ")); 
    one.add(NameText); 
    two.add(new JLabel("Address ")); 
    two.add(AddressText); 
    three.add(new JLabel("City ")); 
    three.add(CityText); 
    four.add(new JLabel("State ")); 
    StateList.setSelectedIndex(0); 
    four.add(StateList); 
    four.add(new JLabel("ZIP")); 
    four.add(ZipText); 
    four.add(new JLabel("Phone")); 
    four.add(PhoneText); 
    JButton addwho = new JButton("Add " + who); 
    addwho.setMnemonic('A'); 
    JButton close = new JButton("Exit"); 
    close.setMnemonic('C'); 
    JButton deleteFile = new JButton("Delete File"); 
    deleteFile.setMnemonic('D'); 
    five.add(addwho); 
    five.add(close); 
    five.add(deleteFile); 
    MessageTextContractors.setEditable(false); 
    MessageTextContractors.setHorizontalAlignment(JTextField.CENTER); 

    six.add(MessageTextContractors); 
    c.add(one); 
    c.add(two); 
    c.add(three); 
    c.add(four); 
    c.add(five); 
    c.add(six); 

    deleteFile.setToolTipText("Delete File"); 
    addwho.setToolTipText("Add "+ who); 
    close.setToolTipText("Exit");
    if (who == "Contractor")
        addwho.addActionListener(addConHandler); 
    close.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) { 
            NameText.setText(""); 
            AddressText.setText(""); 
            CityText.setText(""); 
            ZipText.setText(""); 
            PhoneText.setText(""); 
            MessageTextContractors.setText(""); 
            popWindow.dispose(); 
        }
    }
); 
deleteFile.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent e) { 
MessageTextContractors
.setText(""); 
if (who.equals("Contractor")) { 
File file = new File("Contractor.txt"); 
boolean conFileDeleted = file.delete(); 
if (conFileDeleted) { 
MessageTextContractors 
.setText("Contractor file has been deleted"); 
} else { 
MessageTextContractors 
.setText("There was an error in deleting file");
}
}
}
}
); 
} 
class AddContButtonHandler implements ActionListener { 
    public void actionPerformed(ActionEvent addConHandler) { 
        int StateIndex; 
        try { 
            File file = new File("Contractor.txt"); 
            StringBuilder sb = new StringBuilder(); 
            boolean success = file.createNewFile();
            if (success) { 
                MessageTextContractors 
                .setText("Contractor.txt file created file added"); 
            } else if (file.canWrite()) { 
                MessageTextContractors 
                .setText("Writing data to Contractor.txt, file added"); 
            } else { 
                MessageTextContractors.setText("Cannot create file: Contractor.txt"); 
            } 
try {
    FileWriter fileW = new FileWriter("Contractor.txt", true); 
    sb.append(NameText.getText()); 
    sb.append("\n"); 
    sb.append(AddressText.getText()); 
    sb.append("\n"); 
    sb.append(CityText.getText()); 
    sb.append("\n"); 
    StateIndex = StateList.getSelectedIndex(); 
    sb.append(states[StateIndex]); 
    sb.append("\n"); 
    sb.append(ZipText.getText()); 
    sb.append("\n"); 
    sb.append(PhoneText.getText()); 
    sb.append("\r\n"); 
    fileW.write(sb.toString()); 
    parent.setField(sb.toString()); 
    fileW.close(); 
    MessageTextContractors.setText("A new Contractor has been added!"); 
    ExistTextContractors.setText ("File Contractor.txt exists and can be read from!");
    FileReader fileR = new FileReader("Contractor.txt"); 
    BufferedReader buffIn = new BufferedReader(fileR); 
    String textData = buffIn.readLine(); 
    buffIn.close();

} 
catch (IOException e1) { 
    JOptionPane.showMessageDialog(null, e1.getMessage(), "ERROR", 2); 
} 
NameText.setText(""); 
AddressText.setText(""); 
CityText.setText(""); 
ZipText.setText(""); 
PhoneText.setText(""); 
} 
        catch (IOException e1) { 
        }
    }
}



public void actionPerformed(ActionEvent event){ 
} 
private void Exit_pressed(){ 
System.exit(0); 
} 
}