System.NullPointerException: Attempt to de-reference a null object
External entry point "Any suggestions will really help. Thanks in advance.Code Piece:<apex:page controller="SinglepicklistforMyBook" action="{!autoRun}" sidebar="false"> <apex:form > <table align="center" cellpadding="15" > <td>Select Property Type :-</td> <td><apex:selectList size="4" value="{!SelectValue}" multiselect="true"> <apex:selectOptions value="{!statusOptions}"/> </apex:selectList></td> <tr> <td>List of Selected Values For Books of Type:</td> <td><apex:outputText label="You have selected:" value="{!SelectValue}" /> </td> </tr> <div align="center" draggable="false" > <apex:commandButton style="float:centre" value="Show Result" onclick="{!ShowResult}"/> <apex:actionSupport reRender="refresh" event="onkeyup" /> </div> <apex:pageBlock > <apex:pageblockTable align="center" cellpadding="15" value="{!ShowResult}" var="O" title="List of Selected Books"> <apex:column value="{!O.Name}"/> <apex:column value="{!O.Status_Book__c}"/> </apex:pageblockTable> </apex:pageBlock> </table> </apex:form></apex:page>*************************Controller*************************public with sharing class SinglepicklistforMyBook {public List<SelectOption> statusOptions { get;set; }public List<String> selectValue {get;set;} //for multiselect // public string selectValue { get;set; } //in case multiselect =false List<Book__c> showresult; public List<Book__c> getShowResult() { //showresult= [Select Name, Status_Book__c from Book__c where Status_Book__c = :selectValue ]; // for multiselect = false showresult= [Select Name, Status_Book__c from Book__c where Status_Book__c IN :selectValue]; //for multiselect return showresult; }public void autoRun(){ Schema.DescribeFieldResult statusFieldDescription = Book__c.Status_Book__c.getDescribe(); statusOptions = new list<SelectOption>(); for (Schema.Picklistentry picklistEntry : statusFieldDescription.getPicklistValues()) { statusOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel())); }}}
Use this code
public with sharing class SinglepicklistforMyBook {
public List<SelectOption> statusOptions { get;set; }
public List<String> selectValue {get;set;} //for multiselect
public SinglepicklistforMyBook(){
statusOptions = new List<SelectOption>();
}
// public string selectValue { get;set; } //in case multiselect =false
List<Book__c> showresult;
public List<Book__c> getShowResult() {
if(selectValue!=null){
//showresult= [Select Name, Status_Book__c from Book__c where Status_Book__c = :selectValue ]; // for multiselect = false
showresult= [Select Name, Status_Book__c from Book__c where Status_Book__c IN :selectValue]; //for multiselect
return showresult;
}else{
return null ;
}
}
public void autoRun()
{
Schema.DescribeFieldResult statusFieldDescription = Book__c.Status_Book__c.getDescribe();
statusOptions = new list<SelectOption>();
for (Schema.Picklistentry picklistEntry : statusFieldDescription.getPicklistValues())
{
statusOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
}
}
}