+ Start a Discussion
RishavRishav 

Error: Compile Error: Constructor not defined: [test2].<Constructor>() at line 9 column 16

@isTest
public class test2_test{
   public static testMethod void getDataTest()
   {
     property__c ptest = new property__c(name='test',type__c='1-bhk',lease_term__c = 1,address__c = 'testAddress',parking__c='depend upon owner');
     insert ptest;
    // apexpages.standardsetcontroller ssc = new apexpages.standardsetcontroller(ptest);
  
    test2 t2 = new test2();
    t2.getData();
   }
 
}

 i am getting continuously same error message . please tell me where i am exactly making the mistake.
Best Answer chosen by Rishav
kiranmutturukiranmutturu
try this

@isTest
public class test2_test{
   public static testMethod void getDataTest()
   {
     property__c ptest = new property__c(name='test',type__c='1-bhk',lease_term__c = 1,address__c = 'testAddress',parking__c='depend upon owner');
     insert ptest;
    // apexpages.standardsetcontroller ssc = new apexpages.standardsetcontroller(ptest);
 
List<property__c> prps = new List<property__c>();
prps.add( [ Select Id From property__c] );

test2 t2 = new test2(new ApexPages.StandardSetController( prps ));
  
  
    t2.getData();
   }

}

All Answers

kiranmutturukiranmutturu
could you post the test2 class?.. 
RishavRishav
// this is my test2 class code

public class test2 {
public string countries {get;set;}
string[]states = new string[]{};
string[]cities = new string[]{};
string[] flatTypes = new string[]{};
public string beds{get;set;}
public string toBeds{get;set;}
public string fromBaths{get;set;}
public string toBaths{get;set;}
public string fromBeds{get;set;}
public string fromRents{get;set;}
public string toRents{get;set;}
public string  fromSfs{get;set;}
public string  toSfs{get;set;}
public string status{get;set;}
public string searchText{get;set;}

public string[] getflatTypes()
{
   return flatTypes;
}
  public void setFlatTypes(string[] flatTypes)
  {
   this.flatTypes = flatTypes;
  }

public string[] getcities()
{
   return cities;
}
public void setCities(string[] cities)
{
   this.cities = cities;
}

public string[] getStates()
{
   return states;
}

public void setstates(string[] states)
{
   this.states = states;
}
public apexpages.standardsetcontroller ssc{get;private set;}
     
    public test2(ApexPages.StandardSetController controller)
   
    {
      ssc = new apexpages.standardsetcontroller([select id,picture__c,address__c,zip__c,type__c,bathrooms__c,bedrooms__c,status__c,
      contact_number__c,rent__c,year_Built__c,name,lease_term__c from property__c]);
    }


    // code section for fetching the data from database
   
   
    public list<property__c> getData()
    {
     return (list<property__c>) ssc.getRecords();
     }
   
   
    // this is the end of the data retrieval code section
   


  //  public String flatTypes { get; set; }


  public list<selectoption> getCountry()
  {
   list<selectoption>options = new list<selectoption>();
   options.add(new selectoption('India','India'));
   options.add(new selectoption('US','US'));
    return options;
  }
 
  public list<selectoption>getState()
  {
    list<selectoption>stoption = new list<selectoption>();
     if(countries=='india')
     {
    stoption.add(new selectoption('Bihar','Bihar'));
    stoption.add(new selectoption('AP','AP'));
    }
    return stoption;
  }   // till here no problem in the code
 
  // starting the code for city checkbox
 
   public list<selectoption> getCity()
   {
    list<selectoption> cityoptions = new list<selectoption>();
    for(string s :states)
    {
      if(s=='Bihar')
      {
    cityoptions.add(new selectoption('Patna','patna'));
    cityoptions.add(new selectoption('Gaya','Gaya'));
    cityoptions.add(new selectoption('Rajagir','Nalanda'));
    cityoptions.add(new selectoption('Mujaffarpur','Mujaffarpur'));
    cityoptions.add(new selectoption('Darbhanga','Darbhanga'));
    }
     if(s=='Ap')
     {
    cityoptions.add(new selectoption('Hyderabad','Hyderabad'));
    cityoptions.add(new selectoption('vizag','vizag'));
    cityoptions.add(new selectoption('vijaywada','vijaywada'));
    cityoptions.add(new selectoption('warangal','warangal'));
    cityoptions.add(new selectoption('Trichi','Trichi'));
    }
    }
    return cityoptions;
   }
  
   // code for flat type
   public list<selectoption> getflatType()
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('1-BHK','1-BHK'));
     options.add(new selectoption('2-BHK','2-BHK'));
    
      return options;
   }
  
   // code for bed range
    public list<selectoption> getBed()
   {
     list<selectoption>options = new list<selectoption>();
          options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('1','1'));
     options.add(new selectoption('2','2'));
     options.add(new selectoption('3','3'));
     options.add(new selectoption('4','4'));
     options.add(new selectoption('5','5'));
     return options;
   }
  
   // code for bed range
    public list<selectoption> getToBed()
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('1','1'));    
     options.add(new selectoption('2','2'));
     options.add(new selectoption('3','3'));
     options.add(new selectoption('4','4'));
     options.add(new selectoption('5','5'));
     return options;
   }
  
   // code for bathroom range
  
   // code for bed range
    public list<selectoption> getFromBath()
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('1','1'));    
     options.add(new selectoption('2','2'));
     options.add(new selectoption('3','3'));
     options.add(new selectoption('4','4'));
     options.add(new selectoption('5','5'));
     return options;
   }
    public list<selectoption> getToBath()
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('1','1'));    
     options.add(new selectoption('2','2'));
     options.add(new selectoption('3','3'));
     options.add(new selectoption('4','4'));
     options.add(new selectoption('5','5'));
     return options;
   }
  
   // code for rent range
  
     public list<selectoption> getFromRent()        // function for from rent list option
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('5000','5000'));    
     options.add(new selectoption('10000','10000'));
     options.add(new selectoption('15000','15000'));
     options.add(new selectoption('20000','20000'));
     options.add(new selectoption('25000','25000'));
     return options;
   }
  
     public list<selectoption> getToRent()                 // function for toRent section
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('5000','5000'));    
     options.add(new selectoption('10000','10000'));
     options.add(new selectoption('15000','15000'));
     options.add(new selectoption('20000','20000'));
     options.add(new selectoption('25000','25000'));
     return options;
   }
   // code section for square foot range
  
  
     public list<selectoption> getFromSF()                 // function for from square foot section
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('1000','1000'));    
     options.add(new selectoption('2000','2000'));
     options.add(new selectoption('3000','3000'));
     options.add(new selectoption('4000','4000'));
     options.add(new selectoption('5000','5000'));
     return options;
   }
  
  
     public list<selectoption> getToSF()                 // function for  TO square foot section
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('2000','2000'));
     options.add(new selectoption('3000','3000'));
     options.add(new selectoption('4000','4000'));
     options.add(new selectoption('5000','5000'));
       options.add(new selectoption('6000','6000'));
     return options;
   }
  
   // code for status option
  
     public list<selectoption> getstatus_options()                 // function for STATUS picklist
   {
     list<selectoption>options = new list<selectoption>();
     options.add(new selectoption('--none--','--none--'));
     options.add(new selectoption('occupied','occupied'));
     options.add(new selectoption('REO','REO'));
     options.add(new selectoption('Unknown','Unknown'));
     options.add(new selectoption('Vacant prep','Vacant prep'));
     options.add(new selectoption('vacant Ready','vacant Ready'));
     options.add(new selectoption('vacant soon','vacant soon'));

     return options;
   }
}
kiranmutturukiranmutturu
try this

@isTest
public class test2_test{
   public static testMethod void getDataTest()
   {
     property__c ptest = new property__c(name='test',type__c='1-bhk',lease_term__c = 1,address__c = 'testAddress',parking__c='depend upon owner');
     insert ptest;
    // apexpages.standardsetcontroller ssc = new apexpages.standardsetcontroller(ptest);
 
List<property__c> prps = new List<property__c>();
prps.add( [ Select Id From property__c] );

test2 t2 = new test2(new ApexPages.StandardSetController( prps ));
  
  
    t2.getData();
   }

}
This was selected as the best answer
Vinit_KumarVinit_Kumar
Hey Rishav,

Try below code :-

@isTest
public class test2_test{
   public static testMethod void getDataTest()
   {
     property__c ptest = new property__c(name='test',type__c='1-bhk',lease_term__c = 1,address__c = 'testAddress',parking__c='depend upon owner');
     insert ptest;
     apexpages.standardsetcontroller ssc = new apexpages.standardsetcontroller(ptest);
  
    test2 t2 = new test2(ssc);
    t2.getData();
   }
 
}

If this helps,please mark it as best answer to help others :)
RishavRishav
Hiii Vinit ,
               i am still getting the same error with your code also.
RishavRishav
HIii Kiran ,
                  Thanks for your answer , my problem solved. 
          Now please tell me wherer i was doing the error otherwise everytime i will stuck at the same place . so please tell me the exact reason of this error.
Vinit_KumarVinit_Kumar
Ohk just saw,you are passing a list of records in your constructor.So,replace it with a list and then you are good to go,something like below :-

@isTest
public class test2_test{
   public static testMethod void getDataTest()
   {
     property__c ptest = new property__c(name='test',type__c='1-bhk',lease_term__c = 1,address__c = 'testAddress',parking__c='depend upon owner');
     insert ptest;
	 
         //creating a list
	 List<property__c> prList = [select id from property__c where id =:ptest.id];
     apexpages.standardsetcontroller ssc = new apexpages.standardsetcontroller(prList);
  
    test2 t2 = new test2(ssc);
    t2.getData();
   }
 
}




kiranmutturukiranmutturu
on a high level 

test2 t2 = new test2(); this will call a default construtor which you dont have as you overrided with standardsetcontroller

so we did in that above way...see this once  http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
RishavRishav
Thanks vinit and kiran , now i exactly got what mistake i was doing . 

Thanks to both  of  you 
 Rishav