Timeline for "Attempt to de-reference a null object" on VF page
Current License: CC BY-SA 4.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 3, 2019 at 18:34 | vote | accept | PHonnold | ||
Nov 5, 2018 at 22:45 | comment | added | gNerb |
The difference between pricebook_name = new List<SelectOption(); and List<SelectOption> pricebook_name = new List<SelectOption(); is simply that in the latter you declare and initialize in the same line. In the former it assumes you declare the variable earlier in the code using List<SelectOption> pricebook_name; and then you call pricebook_name = new List<SelectOption>(); on a different line. Ultimately, they accomplish the exact same thing.
|
|
Nov 5, 2018 at 21:05 | comment | added | Jayant Das |
@PHonnold - because you are using pricebook_name on the VF page, so you need to have it declared at the class level (outside the method where you are populating it) with a getter method. And that the variable needs to be initialized, so that you can add values in it.
|
|
Nov 5, 2018 at 20:42 | comment | added | PHonnold | So it seems I don't fully understand variable assignment here. I had the following assignment outside the code block that was shown. public List<SelectOption> pricebook_name; I tried the option that was posted above 'pricebook_name = new List<selectOption>();' but got the error message that the pricebook_name variable could not be found. I had to change it to the setup that Jayant Das talked about below 'List<SelectOption> pricebook_name = new List<SelectOption>();' Testing this fully right now, but not sure why the one worked and the other didn't. | |
Nov 5, 2018 at 19:48 | history | answered | gNerb | CC BY-SA 4.0 |