function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
simhasimha 

ERROR MESSAGE --> System.NullPointerException: Argument 1 cannot be null in SELECTOPTION

 Hello EveryBody,

                 

                      Im Creating an Apex page where  i have selectList whose options want to be  taken from a query

In this im Getting Error as

 

System.NullPointerException: Argument 1 cannot be null 

 

 

and my APEX CODE IS 

 

public class posi
{
    LIST<selectoption> statusoptns =new list<selectoption>();
    string valuename;
    public void setvaluename(string valuename)
    {
        this.valuename='manager';
    }
    public string getvaluename()
    {
        return valuename;
    }
    string s='SELECT A VALUE';
    public void setvalus()
    {
        for(Position__c ptr: [SELECT Position__c.Status__c from Position__c])
        {

// This if statement is just to check where error is getting but i cant done it 
            if(ptr.Status__c==' ')
            {
                 s='abc';
            }
            else
            {           


             //If i remove the add options in this else area im getting output only 'SELECT A VALUE'

                     statusoptns.add(new selectoption(ptr.Status__C,ptr.Status__c));
            }
        }
    }
    public list<selectoption> getvalus()
    {       
        statusoptns.add(new selectoption(s,s));
        setvalus();
        return statusoptns;
    }
}

 

 

and my Visual force page code is

 

 

<apex:page controller="posi">
<apex:form >
<apex:pageBlock ><apex:pageBlockSection >
    <apex:outputLabel value="VALUES" for="sel">
    <apex:selectList value="{!valuename}" size="1" id="sel">
        <Apex:selectOptions value="{!valus}">       
        </Apex:selectOptions>
    </apex:selectList></apex:outputLabel>
</apex:pageBlockSection></apex:pageBlock>
</apex:form>   
</apex:page>

 

 

If any Body knows how to solve it help me as soon as possible

Message Edited by simha on 05-08-2009 05:23 AM
jeffdonthemicjeffdonthemic

See if this blog post helps you: http://blog.jeffdouglas.com/2008/11/25/dependent-multilevel-selectlists/

 

Jeff Douglas

Informa Plc

http://blog.jeffdouglas.com

kerwintangkerwintang

Maybe because the case of the first parameter is incorrect?

 

statusoptns.add(new selectoption(ptr.Status__C,ptr.Status__c));

 

the 1st param is ptr.Status__C while the 2nd one is ptr.Status__c (small letter c)

 

Have you tried this? Thanks.

 

Regards,
Kerwin

simhasimha

thank u very much for ur help but i got the error by changing the following code

 

  if(ptr.Status__c==' ')
            {
                 s='abc';
            }

 

above to this one

 

  if(ptr.Status__c==null)
            {
                 s='abc';
            }

kerwintangkerwintang
The error refers to Argument, though. It's possible that the value for ptr.Status__c = ' ' that's why there is no error when you used the 1st code. When you use the 2nd code, the condition "if(ptr.Status__c==null" is not satisfied that's why it goes to the "else" condition which possibly throws the error.