我正在编写一个简单的按钮,可在单击时创建新的联系人。我知道这个错误是由于公开声明和私人声明而发生的,但我无法弄清楚这是发生了什么。我已经导入了联系的课程,但我被困住了。
import java.util.*;
class Contact {
private List<Contact> contacts = new LinkedList<Contact>();
private int nextId = 0;
public Contact add(Contact contact) {
contact.setId(++nextId);
contacts.add(contact);
return contact;
}
private String firstName = "";
private String lastName = "";
private String email = "";
这是代码呼叫联系人
import domain.*;
import javax.swing.JOptionPane;
public class MainUI extends javax.swing.JFrame {
private Account account = null;
public void setAccount(Account account) {
this.account = account;
}
Contact contact = new Contact(); // Error is here
contact.setFirstname(firstNameFld.getText());
contact.setLastname(lastNameFld.getText());
contact.setEmail(emailFld.getText());
contact.setPhone(phoneFld.getText());
boolean isValid = contact.validate();
if(!isValid) {
JOptionPane.showMessageDialog(this, "All fields are required for a Contact", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
JOptionPane.showMessageDialog(this, "Your new Contact has been saved", "Saved Contact", JOptionPane.INFORMATION_MESSAGE);
firstNameFld.setText("");
lastNameFld.setText("");
emailFld.setText("");
phoneFld.setText("");
}
答案 0 :(得分:0)
您的联系类是私有的,将其更改为公开或将类移动到同一个包。