“线程中的异常”;“主要”;java.lang.UnsupportedOperationException:尚不受支持

“线程中的异常”;“主要”;java.lang.UnsupportedOperationException:尚不受支持,java,Java,所以前几天我有一个悬而未决的问题,我认为我能够解决我的问题,我明白发生了什么,但现在我遇到了一个新问题。我对编程非常陌生,这是我正在上的一门课。我正在尝试创建一个使用继承、多态性和集合的联系人列表。我需要一个联系人列表,其中存储两种类型的联系人:商务和个人。我需要提示1添加联系人,然后要求1提供个人信息或要求2提供业务信息。提示2将允许用户显示所选联系人的输出,提示3将退出 我构建了以下类和子类。我非常确定这些类是正确构建的,但是在添加了任何一种类型的联系人之后,当我选择2查看时,我在线程“ma

所以前几天我有一个悬而未决的问题,我认为我能够解决我的问题,我明白发生了什么,但现在我遇到了一个新问题。我对编程非常陌生,这是我正在上的一门课。我正在尝试创建一个使用继承、多态性和集合的联系人列表。我需要一个联系人列表,其中存储两种类型的联系人:商务和个人。我需要提示1添加联系人,然后要求1提供个人信息或要求2提供业务信息。提示2将允许用户显示所选联系人的输出,提示3将退出

我构建了以下类和子类。我非常确定这些类是正确构建的,但是在添加了任何一种类型的联系人之后,当我选择2查看时,我在线程“main”java.lang.UnsupportedOperationException中遇到异常:还不受支持。这方面的任何帮助都会很棒

我为这篇冗长的帖子道歉,但我想我应该展示所有的东西

这是我的主要课程:

package contactlist;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;

public class ContactList {

/*ArrayList<List.Contact> contactlist;*/

List<Contact> contactlist = new ArrayList<>();


/* Contact contact; */
private int top = 0;

public static void main(String[] args) throws IOException {
    /* Contact contact;
    contact = new Contact();
    List.Contact c;
    c = contact; */
    ContactList list = new ContactList();

    BufferedReader keyIn;
    keyIn = new BufferedReader(new InputStreamReader(System.in));
    String choose = "";
    while (true) {

        System.out.println("\n[1] Add contact");
        System.out.println("[2] View all contacts");
        System.out.println("[3] Quit");
        System.out.print("Choose : ");

        try {
            choose = keyIn.readLine();
        } catch (IOException e) {

            System.out.println("Error");
        }
        switch (choose) {
            case "1":
                list.addContact();
                break;
            case "2":
                list.viewContacts();
                break;
            case "3":
                System.exit(0);
                break;
            default:
                System.out.println("Error");
                break;
         }

       }
    }

public ContactList() {
    this.contactlist = new ArrayList<>();
}

public void addContact() throws IOException {
    BufferedReader keyIn;
    keyIn = new BufferedReader(new InputStreamReader(System.in));
    String firstName;
    String lastName;
    String address;
    String email;
    String phone;
    String jobTitle;
    String organization;
    String dateOfBirth;

    Scanner input = new Scanner(System.in);
    System.out.println("Please enter Specify the contact type (1) Personal
    or (2) Business: ");
    int contactType = input.nextInt();
    if (contactType == 1) {
        System.out.print("First Name: ");
        firstName = keyIn.readLine();
        System.out.print("Last Name: ");
        lastName = keyIn.readLine();
        System.out.print("Address: ");
        address = keyIn.readLine();
        System.out.print("E-mail address: ");
        email = keyIn.readLine();
        System.out.print("Phone number: ");
        phone = keyIn.readLine();
        System.out.print("Date of Birth (MM/DD/YYYY): ");
        dateOfBirth = keyIn.readLine();

        PersonalContact entry;
        entry = new PersonalContact(firstName, lastName, address, email, 
        phone, dateOfBirth);
        contactlist.add(entry);
        top++;
        try {
            entry.write();
        } catch (Exception e) {
        }

    } else if (contactType == 2) {
        System.out.print("First Name: ");
        firstName = keyIn.readLine();
        System.out.print("Last Name: ");
        lastName = keyIn.readLine();
        System.out.print("Address: ");
        address = keyIn.readLine();
        System.out.print("E-mail address: ");
        email = keyIn.readLine();
        System.out.print("Phone number: ");
        phone = keyIn.readLine();
        System.out.print("Job Title: ");
        jobTitle = keyIn.readLine();
        System.out.print("Organization: ");
        organization = keyIn.readLine();

        BusinessContact entry;
        entry = new BusinessContact(firstName, lastName, address, email, 
        phone, jobTitle, organization);
        contactlist.add(entry);
        top++;
        try {
            entry.write();
        } catch (Exception e) {
        }

    }

}

public void view() {
for (int index = 0; index < top; index++) {
    contactlist.get(index).viewContacts();
    }
    }

private void viewContacts() {
    throw new UnsupportedOperationException("Not supported yet."); //To 
change body of generated methods, choose Tools | Templates.
}
}
业务联系人子类:

package contactlist;

    public class BusinessContact extends Contact {

    private String jobTitle;
    private String organization;

    public BusinessContact(String firstName, String lastName, String 
    address, String email, String phone, String jobTitle, String 
    organization) { 
    super(firstName, lastName, address, email, phone);
    this.jobTitle = jobTitle;
    this.organization = organization;
}

public String getJobTitle() {
    return jobTitle;
}

public void setJobTitle(String jobTitle) {
    this.jobTitle = jobTitle;
}

public String getOrganization() {
    return organization;
}

public void setOrganization(String organization) {
    this.organization = organization;
}

void write() {
    throw new UnsupportedOperationException("Not supported yet."); //To 
    change body of generated methods, choose Tools | Templates. 
}

public void viewContacts() {
super.viewContacts();
System.out.println(this.getOrganization());
System.out.println(this.getJobTitle());
}
}
package contactlist;

    public class PersonalContact extends Contact {

    private String dateOfBirth;

    public PersonalContact(String firstName, String lastName, String
    address, String email, String phone, String dateOfBirth) {
    super(firstName, lastName, address, email, phone);
    this.dateOfBirth = dateOfBirth;
}

public String getdateOfBirth() {
    return dateOfBirth;
}

public void setdateOfBirth(String dateOfBirth){
    this.dateOfBirth = dateOfBirth;
}


void write() {
    throw new UnsupportedOperationException("Not supported yet."); //To
    change body of generated methods, choose Tools | Templates. 
}

public void viewContacts() {
super.viewContacts();
System.out.println(this.dateOfBirth);
}
}
个人联系人子类:

package contactlist;

    public class BusinessContact extends Contact {

    private String jobTitle;
    private String organization;

    public BusinessContact(String firstName, String lastName, String 
    address, String email, String phone, String jobTitle, String 
    organization) { 
    super(firstName, lastName, address, email, phone);
    this.jobTitle = jobTitle;
    this.organization = organization;
}

public String getJobTitle() {
    return jobTitle;
}

public void setJobTitle(String jobTitle) {
    this.jobTitle = jobTitle;
}

public String getOrganization() {
    return organization;
}

public void setOrganization(String organization) {
    this.organization = organization;
}

void write() {
    throw new UnsupportedOperationException("Not supported yet."); //To 
    change body of generated methods, choose Tools | Templates. 
}

public void viewContacts() {
super.viewContacts();
System.out.println(this.getOrganization());
System.out.println(this.getJobTitle());
}
}
package contactlist;

    public class PersonalContact extends Contact {

    private String dateOfBirth;

    public PersonalContact(String firstName, String lastName, String
    address, String email, String phone, String dateOfBirth) {
    super(firstName, lastName, address, email, phone);
    this.dateOfBirth = dateOfBirth;
}

public String getdateOfBirth() {
    return dateOfBirth;
}

public void setdateOfBirth(String dateOfBirth){
    this.dateOfBirth = dateOfBirth;
}


void write() {
    throw new UnsupportedOperationException("Not supported yet."); //To
    change body of generated methods, choose Tools | Templates. 
}

public void viewContacts() {
super.viewContacts();
System.out.println(this.dateOfBirth);
}
}

viewContacts()
方法的实现只会引发此异常。如果你想要一个不同的行为,你必须实现它。例如,一个微不足道的实现:

private void viewContacts() {
    System.out.println (contactlist);
}

我猜
java.lang.UnsupportedOperationException
源于您尚未实现的方法,它显然抛出了
java.lang.UnsupportedOperationException
。您的代码抛出了它,这真的不需要天才,当你的代码充满了抛出异常的地方?!异常的堆栈跟踪向您显示了它被抛出的确切位置,这是从您抛出该异常的代码中得到的。