You need to sign in to do that
Don't have an account?
SelectOption error
Hi,
I am getting an error and not able to able to figure out what the issue is. Please throw your ideas.
Below is the code:
1 public class testing
2 {
3 String strQ1Opt1='0-20 million';
4 List<SelectOption> lstSelOptQ1;
5 lstSelOptQ1 = new List<SelectOption>();
6 lstSelOptQ1.add(new SelectOption(strQ1Opt1,strQ1Opt1,false));
7 }
Error: Compile Error: unexpected token: '=' at line 5 column 16
-------------------------------------------------------------------------------------------------------------------------------------------
And when i change the code pasted as below, a different error is thrown.
Code:
1 public class testing
2 {
3 String strQ1Opt1='0-20 million';
4 List lstSelOptQ1 = new List();
5 lstSelOptQ1.add(new SelectOption(strQ1Opt1,strQ1Opt1,false));
6 }
Error:Compile Error: expecting a right parentheses, found 'new' at line 5 column 20
Please point out any issues in the above code.
Thanks.
Asif
that would solve one issue, but unless he puts the "add" operation into a method, it'll still error out
All Answers
you need to either instantiate the list upon declaration or do it in a method:
option 1:
option 2:
Hi Aasif,
The only issue I could point out in the above code is here
1 public class testing
2 {
3 String strQ1Opt1='0-20 million';
4 List lstSelOptQ1 = new List();
5 lstSelOptQ1.add(new SelectOption(strQ1Opt1,strQ1Opt1,false));
6 }
Error:Compile Error: expecting a right parentheses, found 'new' at line 5 column 20
you are not defining the List type, can you change it to :
List<SelectOption> lstSelOptQ1 = new List<SelectOption>();
that would solve one issue, but unless he puts the "add" operation into a method, it'll still error out
Thanks Steven. That solved the issue.:smileyhappy: