Java no suitable constructor found -


for assignment have created class called agency store data talent agencies , have created required attributes. i've been given data file need read from. first test class. can use getter , setters fine display desired output want create new instance of object agency , add details error message saying no suitable constructor found. have matched settings constructor or @ least can't see mistake is. thanks.

public class agency {      //attributes class agency      private string name;     private string[] address;     private string[] adminstaff;     private int phonenumber;     private string type;      /**      *constructor creates object agency       */     public agency() {      }      /**      * constructor creates object agency values      * @param name      * @param address      * @param adminstaff      * @param phonenumber      * @param type       */     public agency(string name, string[] address, string[] adminstaff, int phonenumber, string type) {         this.name = name;         this.address = address;         this.adminstaff = adminstaff;         this.phonenumber = phonenumber;         this.type = type;     }      /**      *       * @return       */     public string getname() {         return name;     }      /**      *       * @param name       */     public void setname(string name) {         this.name = name;     }       /**      *       * @return       */     public string[] getaddress() {         return address;     }      /**      *       * @return       */     public string[] getadminstaff() {         return adminstaff;     }      /**      *       * @return       */     public int getphonenumber() {         return phonenumber;     }      /**      *       * @param phonenumber       */     public void setphonenumber(int phonenumber) {         this.phonenumber = phonenumber;     }      /**      *       * @return       */     public string gettype() {         return type;     }      /**      *       * @param type       */     public void settype(string type) {         this.type = type;     }        private string getarrayasstring(string[] a) {         string result = "";         /*for(int = 0; i<a.length; i++)         {             result += a[i] +" ";         }*/         for(string s: a)         {             result += s + " ";         }         result = result.trim();         return result;     }      private string[] getstringasarray(string a) {         string[] result = a.split(":");         return result;     }      public void setaddress(string address) {         this.address = getstringasarray(address);     }      public void setaddress(string[] address) {         this.address = address;     }      public string getaddressasstring() {         return getarrayasstring(address);     }      public void setadminstaff(string adminstaff) {         this.adminstaff = getstringasarray(adminstaff);     }      public void setadminstaff(string[] adminstaff) {         this.adminstaff = adminstaff;     }      public string getadminstaffasstring() {         return getarrayasstring(adminstaff);     }      @override     public string tostring(){             return name +"\t"+ getaddressasstring() +"\t"+                     getadminstaffasstring() +"\t"+ phonenumber +"\t"+ type + "\n";     } } 

my main class

public class agencytest {  public static void main(string[] args) {         /*a.setname("potters talent agency");     a.setaddress("126-182 ashwood road:potters bar:hertfordshire en6 2:uk");     a.setadminstaff("megan speagle:daron spilman");     a.setphonenumber(2598052);     a.settype("all");     system.out.println(a.getname());     system.out.println(a.getaddressasstring());     system.out.println(a.getadminstaffasstring());     system.out.println(a.getphonenumber());     system.out.println(a.gettype());*/      agency = new agency("potters talent agency, 126-182 ashwood rd: potters bar: hertfordshire en6 2: uk, "              + "megan speegle:daron spilman:leonel striegel:hubert tesoro:nathanial pompey, 2598052, all");     system.out.println(a); } 

} commented out lines work if try 'agency = new agency()' line won't work.

plz novice , using bad terminology not sure if makes sense im trying do.

ok added new constructor takes 1 string error integer value phonenumber. here's code:

`public agency(string csvstring) {         string[] attributes =csvstring.split(",");         int = 0;         for(string s : attributes)         {             switch(i)             {                 case 0:                     this.name = s;                     break;                 case 1:                     this.address = getstringasarray(s);                     break;                 case 2:                     this.adminstaff = getstringasarray(s);                     break;                 case 3:                     this.phonenumber = getintasstring(s);                     break;                 case 4:                     this.type = s;                     break;             } 

i have tried convert string doesn't seem work. more code:

 private string getintasstring(int a){     string result = integer.tostring(a);     return result; }  public string getphonenumberasstring() {     return getintasstring(phonenumber); } public void setphonenumber(int phonenumber){     this.phonenumber = phonenumber; }         i++;     }` 

agency = new agency("potters talent agency ... en6 2: uk, "          + "megan speegle:daron ... 2598052, all"); 

is trying call constructor single string , no such constructor exists.

you need either provide such constructor (which split string component fields), or split string , call current constructor component fields.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -