+ Start a Discussion
Geetha BGeetha B 

Hai , I am getting the following error in wrapper class .

Error Error: wrapperclassinstance Compile Error: Constructor not defined: [wrapperclassinstance.testwrapperclass].<Constructor>(String, Decimal, Decimal, String, String) at line 15 column 22

here is my program

public with sharing class wrapperclassinstance
{
  public wrapperclassinstance() {}

  list<position__c> pos = new list<position__c>();
  list<employee__c> emp = new list<employee__c>();
  list<testwrapperclass> wrapcls = new list<testwrapperclass>();

  public list<testwrapperclass> getlstwrapperdisplay()
  {
      pos = [select name,min_pay__c,max_pay__c from position__c];
      emp = [select name,Passport_Number__c from employee__c];
      for(integer i = 0;i<pos.size();i++)
      {
         wrapcls.add(new testwrapperclass(pos[i].name,pos[i].min_pay__c,pos[i].max_pay__c,emp[i].name,emp[i].passport_number__c));
      }
      return wrapcls;
  }
  public class testwrapperclass
{
  public string pname{get;set;}
  public integer maxsal{get;set;}
  public integer minsal{get;set;}
  public string ename{get;set;}
  public string passportnumber{get;set;}
 
  public testwrapperclass(string pname,integer maxsal,integer minsal,string ename,string passportnumber)
  {
      this.pname= pname;
      this.maxsal=maxsal;
      this.minsal=minsal;
      this.ename=ename;
      this.passportnumber = passportnumber;
     
   }
}
}
Best Answer chosen by Geetha B
Arunkumar RArunkumar R
Hi,

In your wrapper class contain the following parameters,
public testwrapperclass(string pname,integer maxsal,integer minsal,string ename,string passportnumber)
Your are passing values to the above constructor like below,

wrapcls.add(new testwrapperclass(pos[i].name,pos[i].min_pay__c,pos[i].max_pay__c,emp[i].name,emp[i].passport_number__c));

So while passing data to the consturctor make sure the parameter should be same data type as what you have mentioned, For example

wrapcls.add(new testwrapperclass('arun',22,33,'arunkumar','ex233'));

you can try below code for your problem,

wrapcls.add(new testwrapperclass(String.valueOf(pos[i].name),Integer.valueOf(pos[i].min_pay__c),Integer.valueOf(pos[i].max_pay__c),String.valueOf(emp[i].name),String.valueOf(emp[i].passport_number__c)));

All Answers

Arunkumar RArunkumar R
Hi,

In your wrapper class contain the following parameters,
public testwrapperclass(string pname,integer maxsal,integer minsal,string ename,string passportnumber)
Your are passing values to the above constructor like below,

wrapcls.add(new testwrapperclass(pos[i].name,pos[i].min_pay__c,pos[i].max_pay__c,emp[i].name,emp[i].passport_number__c));

So while passing data to the consturctor make sure the parameter should be same data type as what you have mentioned, For example

wrapcls.add(new testwrapperclass('arun',22,33,'arunkumar','ex233'));

you can try below code for your problem,

wrapcls.add(new testwrapperclass(String.valueOf(pos[i].name),Integer.valueOf(pos[i].min_pay__c),Integer.valueOf(pos[i].max_pay__c),String.valueOf(emp[i].name),String.valueOf(emp[i].passport_number__c)));

This was selected as the best answer
Geetha BGeetha B
Thank you Arun