2017-01-17 14 views
0
public class Phone{ 

public String kind; 
public String number; 

    public Phone(String kind, String number) { 
     this.kind = kind; 
     this.number = number; 
    } 
} 

public class ContactData{ 

public String eMail; 

    Phone phone = new Phone("phone", "031234567"); 
    Phone cellphone = new Phone("cellphone", "0499209802"); 

    public ContactData(String eMail, Phone phone, Phone cellphone){ 
     this.eMail = eMail; 
     this.phone = phone; 
     this.cellphone = cellphone; 
    } 
} 

I've tried a lot of things but I keep getting this error我需要给2个对象是在构造函数中的参数,但我在努力寻找做

+1

什么样的第二和第三个参数中,贵'ContactData'构造期望:

您可以通过直接声明时联络资料情况下,像这样创建电话情况下解决这一问题?你传球了什么? –

回答

0

的正确方法有构造函数的参数,你实际上是什么之间的类型不匹配传:

public ContactData(String eMail, Phone phone, Phone cellphone) 

但是您使用的是String对象,而不是一个Phone

new Contact("[email protected]","123","123"); 

你真正需要传递是Phone一个实例:

new Contact("[email protected]",new Phone("phone", "031234567"), 
      new Phone("phone", "031234567")); 
+0

非常感谢! –

0

在你的照片,你试图声明使用带(字符串,字符串,字符串)参数的构造函数联络资料实例,但唯一的构造你需要一个(字符串,电话,电话)。

ContactData contactData1 = new ContactData("[email protected]", new Phone("cellphone", "154789562"), new Phone("cellphone", "1234567890")) 
+0

非常感谢,我认为它会是这样的,但我找不到它! –

相关问题