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
soumyodeep Guha 6soumyodeep Guha 6 

Issue with Null point exception

Hi All,

i have written the below VF page and the controller class code to fecth the records based on two fields that is Date and Language input bythe user in the VF page, but my custom controller class does not seem to work properly and is throwing a null point exception, Can anybody help correct this. The Null pointer issue is being thirown at line  Mlist.add(Ml);

VF page
============================================================
<apex:page sidebar="false" showHeader="false" standardController="Ticket_transaction__c" extensions="MovieController">
<apex:form >
{!Ticket_transaction__c.Movie_Date__c}
 
  <apex:sectionHeader title="Movie Select Page"/>
  <apex:pageblock title="Movie Preference">
  <apex:pageblockSection title="Movie Language Preference" collapsible="false">
  <apex:inputField value="{!tc.Language_preference__c}"/>
  </apex:pageblockSection>
  <apex:pageblockSection title="Movie Date" collapsible="false">
  <apex:inputfield Value="{!tc.Movie_Date__c}" id="MovieDate" />
  <br/><br/>
  <apex:commandButton value="Display Movies.." action="{!MovieList}" />
  <br/><br/>
        <apex:pageBlockTable value="{!Mlist}" var="M" id="Table">
            <apex:column value="{!M.Movie__c}"/>
            <apex:column value="{!M.Theater__c}"/>
            <apex:column value="{!M.Show_TIme__c}"/>
            <apex:column value="{!M.Movie_Language__c}"/>
        </apex:pageBlockTable>
  </apex:pageblockSection>
  </apex:pageblock>
 </apex:form>
</apex:page>
====================================================================

Custom controller
====================================================================
public class MovieController {
 public MovieController(ApexPages.StandardController controller) {
        tc = new Ticket_transaction__c();
    }

public string Language{get;set;}
public Date MovieDate{get;set;}
public Ticket_transaction__c tc{get;set;}
public list<Movie_at_Theater__c> Mlist{get;set;}
public Movie_at_Theater__c Query{get;set;}
public void MovieList()
{
    
  //  Query = new Movie_at_Theater__c();
       System.debug('Language'+tc.Language_preference__c);
   if(tc.Language_preference__c==null){

       System.debug('Date movie'+tc.Movie_Date__c);
       try{
           Mlist = [Select Movie__c, Theater__c, Show_TIme__c, Movie_Language__c, Movie_Date__c from Movie_at_Theater__c where Movie_Date__c=:tc.Movie_Date__c];
       }catch(System.QueryException qe){
           System.debug('Exception'+qe);
       }
             System.debug('MOvies List'+Mlist);
   } 
else
{
    
    list<Movie_at_Theater__c>Templist = [Select Movie__c, Theater__c, Show_TIme__c, Movie_Language__c, Movie_Date__c from Movie_at_Theater__c where Movie_Date__c=:tc.Movie_Date__c]; 
 for( Movie_at_Theater__c Ml : Templist)
 {

     If(tc.Language_preference__c==Ml.Movie_Language__c)
    
 {
   Mlist.add(Ml);  
 }
         System.debug('MOvies List'+Mlist);
 }  
}
}
}
Best Answer chosen by soumyodeep Guha 6
SinghforceSinghforce
Hi Soumyadeep,

You need to initialize the mlist

Include Mlist = new List<Movie_at_Theater__c>(); in the constructor.

Please mark this as solution if it solves your problem.

thanks,
Dilip Singh

All Answers

SinghforceSinghforce
Hi Soumyadeep,

You need to initialize the mlist

Include Mlist = new List<Movie_at_Theater__c>(); in the constructor.

Please mark this as solution if it solves your problem.

thanks,
Dilip Singh
This was selected as the best answer
soumyodeep Guha 6soumyodeep Guha 6
Thanks Dilip it solved the issue :) 
soumyodeep Guha 6soumyodeep Guha 6
Hi Dilip,

need a help with one more thing in this VF page.
the issue is- say 1st i search with language "HIndi" and date 5th and it returned some results but after that i search with language "English" with the same date or any other date but the result of the previous search still gets displayed. How can we stop that i.e. i dont want the result of the previous search to be displayed.

Also i want to prevent search for dates less then the current date, how can i implement that.

thanks in advance

Regards
Soumyodeep