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
pupilstuffpupilstuff 

System.NullPointerException: Attempt to de-reference a null object

Hello Plz resolve this error

 

This is my apex code

 

<apex:page standardController="lib_demo__c" extensions="InventoryDetails1" showHeader="false">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >

<apex:inputField id="Acession_no__c" value="{!lib_demo__c.Acession_no__c}" />

        <apex:commandButton value="Seacrh" action="{!doSearch}"  rerender="block" status="status"/>
       
           <apex:pageBlockTable value="{!results}" var="l" rendered="{!NOT(ISNULL(results))}">
              <apex:column value="{!l.BookTitile__c}"/>
            
           </apex:pageBlockTable>
           

        
            
</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>
</apex:page>

 

 

 

and this is myExtension

 

public class InventoryDetails1 {


public InventoryDetails1(ApexPages.StandardController controller) {}
   String searchText;
   List<lib_demo__c> results;

   public String getSearchText() {
      return searchText;
   }

   public void setSearchText(String s) {
      searchText = s;
   }

   public List<lib_demo__c> getResults() {
      return results;
   }

   public PageReference doSearch() {
  
   results = (List<lib_demo__c>)[FIND :searchText  RETURNING lib_demo__c(BookTitile__c)][0];
  
  
    //  results = (List<lib_demo__c>)[FIND :searchText RETURNING lib_demo__c(lib_demo__c.BookTitile__c)][0];
      return null;
   }

}

Best Answer chosen by Admin (Salesforce Developers) 
pupilstuffpupilstuff

I came to the solution.

 

I had to use <apex:inputText id="searchText" value="{!searchText}"/>

All Answers

Chamil MadusankaChamil Madusanka

Hi,

 

Try these changes,

 

public class InventoryDetails1 {


public InventoryDetails1(ApexPages.StandardController controller) {}
   String searchText;
   List<lib_demo__c> results;

   public String getSearchText() {
      return searchText;
   }

   public void setSearchText(String s) {
      searchText = s;
   }

   public List<lib_demo__c> getResults() {
      return results;
   }

   public PageReference doSearch() {
   results = new List<lib_demo__c>();
   results = (List<lib_demo__c>)[FIND :searchText  RETURNING lib_demo__c(BookTitile__c)][0];
  
  
    //  results = (List<lib_demo__c>)[FIND :searchText RETURNING lib_demo__c(lib_demo__c.BookTitile__c)][0];
      return null;
   }

}

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Chamil's Blog

pupilstuffpupilstuff

Thanks for the solution

 

but still getting the same error .

Its might be any way related to Data Types??

 

i am using  

 

BookTitile__c TextArea(255)

 

Acession_no__c Text

 

 

pupilstuffpupilstuff

I came to the solution.

 

I had to use <apex:inputText id="searchText" value="{!searchText}"/>

This was selected as the best answer