You need to sign in to do that
Don't have an account?
Error on apex code
Hi,
My Scenario is The primary focus of this assignment is to demonstrate a more complex user interaction. The user will select one (or more) accounts on the left, click “Show Selected Accounts” and the results will show in the right.
Class
My code almost ok except show method when i select an account click on “Show Selected Accounts” it getting error..
What wrong in my code..
public with sharing class assignment31cls {
public List<Account> lst {get; set;}
public list<wrapper> listwrap {get; set;}
public class wrapper {
public account acc {get; set;}
public boolean check {get; set;}
public wrapper(account a){
acc=a;
check=false;
}
}
public assignment31cls(){
listwrap =new List<wrapper>();
List<Account > lstacc=[select id,name,phone from account limit 10];
for(Account a:lstacc){
listwrap.add(new wrapper(a));
}
}
public PageReference Show() {
for(wrapper w:listwrap){
if(w.check == true){
lst.add(w.acc);
}
}
return null;
}
}
VF Page
<apex:page controller="assignment31cls">
<apex:form >
<table width="100%">
<tr>
<td width="50%">
<apex:pageBlock >
<apex:commandButton value="Show Selected Accounts" action="{!Show}"/>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockTable value="{!listwrap}" var="w">
<apex:column headerValue="Action">
<apex:inputCheckbox value="{!w.check}" />
</apex:column>
<apex:column value="{!w.acc.name}"/>
<apex:column value="{!w.acc.phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
<td>
<apex:pageBlock >
<apex:pageBlockTable value="{!lst}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table>
</apex:form>
</apex:page>
It would probably be helpful if you posted details on the error.
System.NullPointerException: Attempt to de-reference a null object
Class.Shravan1.assignment31cls.Show: line 45, column 1
your lst property is never initialised, and therefor null.
In your constructor, add :