Java “道”;如果;将公司添加到联系人时出错

Java “道”;如果;将公司添加到联系人时出错,java,if-statement,netbeans,dao,Java,If Statement,Netbeans,Dao,我正在创建一个餐厅预订系统,我已经创建了customer类,但作为该类的一部分,您可以扩展它,以便公司可以添加联系人 我有一个customer类,一个company类和一个TextCustomerDAO类。在DAO内部是我得到错误的地方。当我尝试说“如果是”,然后添加公司联系人“如果不是,那么只添加客户。我可以只添加客户,但当我尝试添加公司联系人时,我会出错 TextCustomerDAO:在if语句后面的错误 contact=companyContact.getContact() 公司类别:

我正在创建一个餐厅预订系统,我已经创建了customer类,但作为该类的一部分,您可以扩展它,以便公司可以添加联系人

我有一个customer类,一个company类和一个TextCustomerDAO类。在DAO内部是我得到错误的地方。当我尝试说“如果是”,然后添加公司联系人“如果不是,那么只添加客户。我可以只添加客户,但当我尝试添加公司联系人时,我会出错

TextCustomerDAO:在if语句后面的错误 contact=companyContact.getContact()

公司类别:

package projects;

public class Company extends Customer {
private String contact;

public Company() {
    super();
    this.contact = null;
}

public Company(int customerId, String customerName, String customerPhone, String customerAddress, String customerEmail, String contact) {
    super(customerId, customerName, customerPhone, customerAddress, customerEmail);
    this.contact = contact;
}    


public String getContact() {
    return this.contact;
}

public void setContact(String contact) {
    this.contact = contact;
}

@Override
public String toString() {
    return super.toString() + "Company Contact" + getContact();
}
 }
很抱歉,如果这是一个明显的错误,但我已经尝试了一段时间来解决这个问题。如果有人可以帮助我或指出正确的方向,将不胜感激


谢谢

您能向我们显示完整的错误消息吗?如果它是堆栈跟踪就更好了。错误:找不到symbol contact=companyContact.getContact();symbol:method getContact()位置:string类型的变量companyContact您正在尝试调用一个方法
getContact()
在一个字符串上!companyContact是一个字符串(定义在上面的一行中,所以您可能想要的是类似于
contact=companyContact;
或一些我看不到的查找。。。
 public class Customer{
private int customerId;
private String customerName;
private String customerPhone;
private String customerAddress;
private String customerEmail;

private static int numberOfCustomers=0;

public Customer()
{
    this.customerId = 0;
    this.customerName = null;
    this.customerPhone = null;
    this.customerAddress = null;
    this.customerEmail = null;
    numberOfCustomers++;
}   

public Customer(int customerId, String customerName, String customerPhone,
        String customerAddress, String customerEmail)
{
    this.customerId = customerId;
    this.customerName = customerName;
    this.customerPhone = customerPhone;
    this.customerAddress = customerAddress;
    this.customerEmail = customerEmail;

    numberOfCustomers++;
}

public static int getNumberOfCustomers() {
    return numberOfCustomers;
}



public int getCustomerId()
{
    return customerId;
}    

public void setCustomerId(int customerId)
{
    this.customerId = customerId;
}      



public String getCustomerName()
{
    return customerName;
}     
public void setCustomerName(String customerName)
{
    this.customerName = customerName;
}     


public String getCustomerPhone()
{
    return customerPhone;
}        
public void setCustomerPhone(String customerPhone)
{
    this.customerPhone = customerPhone;
}


public String getCustomerAddress()
{
    return customerAddress;
}

public void setCustomerAddress(String customerAddress)
{
    this.customerAddress = customerAddress;
}    



public String getCustomerEmail()
{
    return customerEmail;
}

public void setCustomerEmail(String customerEmail)
{
    this.customerEmail = customerEmail;
}              

@Override
public String toString() {
    return  "customer id: " + getCustomerId() + ", " +
            "customer name: " + getCustomerName() + ", " +
            "customer phone: " + getCustomerPhone() + ", " +
            "customer address: " + getCustomerAddress() + ", " +    
            "customer email: " + getCustomerEmail();

}      
 }
package projects;

public class Company extends Customer {
private String contact;

public Company() {
    super();
    this.contact = null;
}

public Company(int customerId, String customerName, String customerPhone, String customerAddress, String customerEmail, String contact) {
    super(customerId, customerName, customerPhone, customerAddress, customerEmail);
    this.contact = contact;
}    


public String getContact() {
    return this.contact;
}

public void setContact(String contact) {
    this.contact = contact;
}

@Override
public String toString() {
    return super.toString() + "Company Contact" + getContact();
}
 }