• buyan47
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

HI ,

 

        I have  written     apex page  for dispalying     questions random ly   form my custom object  ,   while   runing  iam getting System.NullPointerException: Attempt to de-reference a null object  Class.Records20.: line 20, column 1,  , i check ed with console iam getting values ,  i don't know y it is coming ,  i wll show my apex class and   vf and random number gentation calss.

 

Vf page
--------------------------------
<apex:page controller="Records20" sidebar="false" >
<apex:form >
<apex:pageblock Title="Answers the Questions">
<apex:pageBlockButtons location="bottom">

<apex:commandButton value="Submit" action="{!saveAnswer}"/><br/>
</apex:pageBlockButtons>
<apex:repeat value="{!items1}" var="it">
<apex:outputText value="{!it.intSerial}"> </apex:outputText>).&nbsp;<apex:outputText value="{!it.strQuestion}"></apex:outputText>



<apex:SelectRadio value="{!it.answer12}">
<apex:selectoptions value="{!it.itemsWrap}"/>
</apex:SelectRadio><br/>
</apex:repeat>



</apex:pageblock>
YOUR RESULT IS:&nbsp;&nbsp;<apex:outputText value="{!intCount}"></apex:outputText>
</apex:form>
</apex:page>
--------------------------------------
vf page Controller

public class Records20{

public string answer1{set;get;}
public List<selectOption> selItems {get;set;}
public integer intCount{get;set;}
list<wrapperQuestions> objwraplst = new list<wrapperQuestions>();
list<Questiuons__c> ques=new list<Questiuons__c>();


public Records20()
{
list <Questiuons__c> ret=[SELECT id,Question__c,Answers__c,Correctanswer__c FROM Questiuons__c ];
ret = ObjectRandomizer.randomizeList (ret);
integer serial=0;
for(Questiuons__c a :ret )
{
System.debug('aaa'+a);
String s = a.Answers__c;
list<string> st =s.split(',');-----------  i am gettin  that error here
wrapperQuestions objWrap = new wrapperQuestions();
objWrap.strQuestion = a.Question__c;
objWrap.correctAnswer=a.Correctanswer__c;
serial=serial+1;
objWrap.intSerial=serial;
selItems = new List<selectOption>();
for(String str:st)
{
selItems.add(new SelectOption(str,str));

objWrap.itemsWrap=selItems;

}

objwraplst.add(objWrap);

}
}

public void saveAnswer()
{
intCount=0;
for(wrapperQuestions objwrap:objwraplst)
{
system.debug('::::::::::::'+objwrap.answer12);
if(objwrap.answer12==objwrap.correctAnswer)
{
//intCount = intCount+1;
intCount++;
}
}

}
public list<wrapperQuestions> getitems1()
{
return objwraplst;
}


public class wrapperQuestions
{
public string strQuestion{get;set;}
public integer intSerial{get;set;}
public List<selectOption> itemsWrap {get;set;}
public string answer12{set;get;}
public string correctAnswer{set;get;}

}

}
-------------------------------------------------------------
// Random Number generation
public class ObjectRandomizer {

public static list<Questiuons__c> randomizeList (list<Questiuons__c> Records){

list <Questiuons__c> retList = new list <Questiuons__c>();

while (records.size()>0){
system.debug('++++++' + records.size());
retList.add(records.remove(getRandomInt(records.size())));
}

return retList;
}

public static Integer getRandomInt (Integer num){
Double d = math.random() * num;
return d.intValue();
}

}

  when i  check console iam getting values , console is

3:53:29.055 (55560000)|SYSTEM_METHOD_EXIT|[21]|String.valueOf(Object)
23:53:29.055 (55568000)|HEAP_ALLOCATE|[21]|Bytes:95
23:53:29.055 (55578000)|SYSTEM_METHOD_ENTRY|[21]|System.debug(ANY)
23:53:29.055 (55583000)|USER_DEBUG|[21]|DEBUG|&&&&&&&&&&&&&&(Visible light, Infrared radiation, X-rays and gamma rays, Ultraviolet radiation)
23:53:29.055 (55589000)|SYSTEM_METHOD_EXIT|[21]|System.debug(ANY)
23:53:29.055 (55594000)|STATEMENT_EXECUTE|[23]
23:53:29.060 (60731000)|SYSTEM_METHOD_ENTRY|[19]|System.debug(ANY)
23:53:29.060 (60737000)|USER_DEBUG|[19]|DEBUG|$$$$$$$$$$$Repo rate ,Reverse repo rate,Cash Reserve ratio,base rate
23:53:29.060 (60743000)|SYSTEM_METHOD_EXIT|[19]|System.debug(ANY)
23:53:29.060 (60747000)|STATEMENT_EXECUTE|[20]

  what is the problem , can any one help me

  • September 01, 2012
  • Like
  • 0

We are looking for an experienced Salesforce Developer to join our team in Roseville, CA.  Job requirements include supporting Salesforce projects as well as facilitating training with development team.  Please message me if you are interested.

We are currently in the need of an administrator to provide coverage for maternity leave.  The position is part-time, contract and can be off-site.  You must be located in the United States, preferably in EST or CST.  You should also have experience administering a system for the Software industry.

 

The types of duties will be comparable to SFDC Premier Support plus Admin.

 

If you are interested in being considered for this position, please send a proposal to:

 

Carolee Horner

VersionOne

carolee.horner@versionone.com

 

No phone calls please