0

Facing this error in below code, can someone help me out.

public class mapdepend {
public string mycity {get;set;}
map<string,List<string>> mybranches= new map<string,List<string>>();
public list<selectoption> city{get;set;}
public list<selectoption> branch{get;set;}
  public mapdepend(){
    list<string> hyd = new list<string>();
    hyd.add('SR Nagar');
    hyd.add('LB Nagar');
    List<string>  bang=  new list<string>();
    bang.add('Ecity');
    bang.add('Matahalli');
    mybranches.put('hyd',hyd);
    mybranches.put('bang',bang);
    set<string> keys= mybranches.keyset();
    city=new list<selectoption>();
    branch=new list<selectoption>();
    List<string> my = new list<string>();
    my.add('None');
     for(string a: keys)
      {
        selectoption op1= new selectoption(a,a);
        city.add(op1);
      }
   public pagereference show() {
       for (mycity : mybranches.keyset())
           { 
           branch.add(mybranches.get(mycity));
           }
       return null;
       }
    }
   }
3
  • 1
    your constructor is not closed public mapdepend(){} ....After ` city.add(op1); }` one more close }
    – Ratan Paul
    Commented Mar 16, 2016 at 17:57
  • 1
    Remove the last } and put it after city.add(op1); Commented Mar 16, 2016 at 17:59
  • 2
    For the people who have downvoted this question, pls let know the OP as to why you downvoted the question.
    – Prady
    Commented Mar 16, 2016 at 18:01

1 Answer 1

9

You can't declare a method in your constructor.

Change:

public MyClass
{
    public MyClass()
    {
        // do stuff
        public PageReference show() { }
    }
}

To:

public MyClass
{
    public MyClass()
    {
        // do stuff
    }
    public PageReference show() { }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .