You need to sign in to do that
Don't have an account?
Prallavi Dua
Error:method does not exist or incorrect signature: void clear() from the type string in salesforce
Hi,
Below is my Code: I am getting the error:method does not exist or incorrect signature: void clear() from the type string
Can anyone please help me.
<apex:page controller="Picklist_Controller">
<apex:form>
<apex:pageBlock>
<apex:commandButton value="Show" action="{!Show}"/>
<apex:pageBlockSection title="Countries">
<apex:outputLabel>Country:</apex:outputLabel>
<apex:selectList size="1" value="{!Countries}">
<apex:selectOptions value="{!selectCountries}"/>
</apex:selectList>
</apex:pageBlockSection>
<!-- <apex:selectList value="{!genders}" size="1">
<apex:selectRadio value="{!Selectgender}"></apex:selectRadio>
</apex:selectList>-->
<apex:pageBlockSection title="Hobbies">
<apex:outputLabel>Hobby:</apex:outputLabel>
<apex:selectList value="{!Hobby}" size="1">
<apex:selectOption itemLabel="--None--" itemvalue="None"></apex:selectOption>
<apex:selectOption itemLabel="Swimming" itemvalue="Swimming"></apex:selectOption>
<apex:selectOption itemLabel="Reading" itemvalue="Reading"></apex:selectOption>
<apex:selectOption itemLabel="Cricket" itemvalue="Cricket"></apex:selectOption>
</apex:selectList>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:commandButton action="{!Erase}" value="Clear"/>
</apex:pageBlockSection>
<apex:outputText value="{!SelectedValues}" style="Color:Red"></apex:outputText>
</apex:pageBlock>
</apex:form>
</apex:page>
----------------------------------------------------------------------
public class Picklist_Controller {
public List<SelectOption> selectCountries{get;set;}
// public List<SelectOption> selectGender{get;set;}
public List<SelectOption> selecthobbies{get;set;}
public String Countries{get;set;}
// public String genders{get;set;}
public String Hobby{get;set;}
public String selectedValues{get;set;}
public Picklist_Controller(){
selectCountries = new List<SelectOption>();
// selectGender = new List<SelectOption>();
selectHobbies = new List<SelectOption>();
// selectedValues = new String();
selectCountries.add(new SelectOption('---None--', 'None'));
selectCountries.add(new SelectOption('India','India'));
selectCountries.add(new SelectOption('USA','USA'));
selectCountries.add(new SelectOption('UK','UK'));
/* selectGender.add(new SelectOption('Male','Male'));
selectGender.add(new SelectOption('Female','Female'));*/
/* selectHobbies.add(new SelectOption('Reading','Reading'));
selectHobbies.add(new SelectOption('Swimming','Swimming'));
selectHobbies.add(new SelectOption('Dancing','Dancing'));
selectHobbies.add(new SelectOption('Traveling','Traveling'));*/
}
public void Show(){
selectedValues = 'Selected country:'+countries +'--------'+'Selected Hobby:'+Hobby;
// return null;
}
public void Erase(){
selectedValues.Clear();
}
}
Below is my Code: I am getting the error:method does not exist or incorrect signature: void clear() from the type string
Can anyone please help me.
<apex:page controller="Picklist_Controller">
<apex:form>
<apex:pageBlock>
<apex:commandButton value="Show" action="{!Show}"/>
<apex:pageBlockSection title="Countries">
<apex:outputLabel>Country:</apex:outputLabel>
<apex:selectList size="1" value="{!Countries}">
<apex:selectOptions value="{!selectCountries}"/>
</apex:selectList>
</apex:pageBlockSection>
<!-- <apex:selectList value="{!genders}" size="1">
<apex:selectRadio value="{!Selectgender}"></apex:selectRadio>
</apex:selectList>-->
<apex:pageBlockSection title="Hobbies">
<apex:outputLabel>Hobby:</apex:outputLabel>
<apex:selectList value="{!Hobby}" size="1">
<apex:selectOption itemLabel="--None--" itemvalue="None"></apex:selectOption>
<apex:selectOption itemLabel="Swimming" itemvalue="Swimming"></apex:selectOption>
<apex:selectOption itemLabel="Reading" itemvalue="Reading"></apex:selectOption>
<apex:selectOption itemLabel="Cricket" itemvalue="Cricket"></apex:selectOption>
</apex:selectList>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock>
<apex:pageBlockSection>
<apex:commandButton action="{!Erase}" value="Clear"/>
</apex:pageBlockSection>
<apex:outputText value="{!SelectedValues}" style="Color:Red"></apex:outputText>
</apex:pageBlock>
</apex:form>
</apex:page>
----------------------------------------------------------------------
public class Picklist_Controller {
public List<SelectOption> selectCountries{get;set;}
// public List<SelectOption> selectGender{get;set;}
public List<SelectOption> selecthobbies{get;set;}
public String Countries{get;set;}
// public String genders{get;set;}
public String Hobby{get;set;}
public String selectedValues{get;set;}
public Picklist_Controller(){
selectCountries = new List<SelectOption>();
// selectGender = new List<SelectOption>();
selectHobbies = new List<SelectOption>();
// selectedValues = new String();
selectCountries.add(new SelectOption('---None--', 'None'));
selectCountries.add(new SelectOption('India','India'));
selectCountries.add(new SelectOption('USA','USA'));
selectCountries.add(new SelectOption('UK','UK'));
/* selectGender.add(new SelectOption('Male','Male'));
selectGender.add(new SelectOption('Female','Female'));*/
/* selectHobbies.add(new SelectOption('Reading','Reading'));
selectHobbies.add(new SelectOption('Swimming','Swimming'));
selectHobbies.add(new SelectOption('Dancing','Dancing'));
selectHobbies.add(new SelectOption('Traveling','Traveling'));*/
}
public void Show(){
selectedValues = 'Selected country:'+countries +'--------'+'Selected Hobby:'+Hobby;
// return null;
}
public void Erase(){
selectedValues.Clear();
}
}
selectedValues = ''; OR selectedValues = null;
Thanks
All Answers
selectedValues = ''; OR selectedValues = null;
Thanks