0

Can someone assist us regarding the error message we get. It seems that obj.hasPrevious doesn't have a value. How can we put a condition here that it will return the hasPrevious method if it has a value.

This code is for pagination. Rendering of buttons in VF Page

System.NullPointerException: Attempt to de-reference a null object Class.SearchAdmin2Ctrl.__sfdc_hasPrevious: line 1353, column 1

CONTROLLER:

public Boolean hasPrevious{
    get { return obj.hasPrevious();} set;  
}

CUSTOMITERABLE CLASS THAT IMPLEMENTS ITERATOR:

// for rendering previous button
global boolean hasPrevious(){         
    system.debug('I am in hasPrevious' + i); 
    if(i <= setPageSize) { 
        return false;              
    } else { 
        return true;             
    }    
} 

VF PAGE:

  <apex:commandButton value="< Previous" action="{!previous}" rendered="   {!hasPrevious}" reRender="btable" />

Thank you so much!!

0

I bet obj itself is null that's why accessing obj.hasPrevious() is showing Null pointer exception.

Put a null check before accessing obj.hasPrevious().

Verify the controller code how you are instantiating obj variable.

  • Hi @Santanu, the list of wrapper we used in the obj is a collection list. It can be null if the user is not searching for anything. Is it possible to put an IF condition inside the get that validates if the variable that is used in the query is not null and then that's the time that it will return the method? – lone Mar 28 '17 at 0:57
  • Sure, you have to do that – Santanu Boral Mar 28 '17 at 1:02
  • public Boolean hasPrevious { get { if (!String.isEmpty(wrapFilter1.skillName1)) { return obj.hasPrevious();} } set; } Non-void method might not return a value or might have statement after a return statement. – lone Mar 28 '17 at 1:06
  • You have to use return statement – Santanu Boral Mar 28 '17 at 1:10
  • public Boolean hasPrevious { get { if (!String.isEmpty(wrapFilter1.skillName1)) { } return obj.hasPrevious(); } set; } \ System.NullPointerException: Attempt to de-reference a null object Class.SearchAdmin2Ctrl.__sfdc_hasPrevious: line 1359, column 1 – lone Mar 28 '17 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.