我的对象是Consumer
:
这是一个Consumer
对象具有以下字段并要创建记录。但是报空指针异常。
视觉力量页面:
<apex:page controller="signup1" >
<apex:form >
<h1>User SignUp</h1>
<apex:panelGrid columns="2" style="margin-top:2em;">
<p><b>Name :</b><br />
<apex:inputField id="name" value="{!con.Name}"/>
</p>
<p><b>Address :</b><br />
<apex:inputField id="address" value="{!con.address__c}"/>
</p>
<p><b>Email Id :</b><br />
<apex:inputField required="true" id="emailid" value="{!con.email_id__c}"/>
</p>
<p><b>Password :</b><br />
<apex:inputSecret id="password" value="{!con.password__c}"/>
</p>
<p><b>Confirm Password :</b><br />
<apex:inputSecret id="confirmpassword" value="{!con.Confirm_Password__c}"/>
</p>
<p><b>Security Question :</b><br />
<apex:inputField required="true" id="securityquestion" value="{!con.Security_Question__c}"/>
</p>
<p><b>Answer :</b><br />
<apex:inputField required="true" id="answer" value="{!con.Answer__c}" />
</p>
<p><b>Ph No :</b><br />
<apex:inputField required="true" id="phno" value="{!con.phone__c}"/>
</p>
<p><b>Pan Card No :</b><br />
<apex:inputField required="true" id="pancardno" value="{!con.Pan_Card_No__c}"/>
</p>
<p> <apex:commandButton action="{!registerUser}" value="SignUp" id="SignUp"/></p>
</apex:panelGrid>
</apex:form>
</apex:page>
controller :
public class signup1
{
Consumer__c con = new Consumer__c();
public void signup1()
{
con = [SELECT Name, address__c, email_id__c, password__c, Confirm_Password__c, Security_Question__c, Answer__c, phone__c from Consumer__c where Name =: ApexPages.currentPage().getParameters().get('Name')];
}
public Consumer__c getcon()
{
return con;
}
public PageReference registerUser()
{
try
{
insert Con;
}
catch(System.DMLException e)
{
ApexPages.addMessages(e);
return null;
}
PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
pageRef.setRedirect(true);
return pageRef;
}
}
Consumer
由于 null 异常,我无法将数据插入到对象中。