Reputation: 2983
I am getting the error "Variable does not exist: String"
on the nextOne()
method when calling String.fromCharArray()
. I'm not sure how I'm losing scope of String or it's static methods.
public with sharing class NextLetterGenerator {
public List<String> InputArray;
public Map<String, Integer>Letters;
public Map<Integer, String>Numbers;
public UserIdGenerator(String input) {
InputArray = input.toUpperCase().split('');
InputArray.remove(0);
SetLetters();
SetNumbers();
}
public void SetLetters() {
Letters = new Map<String, Integer> {'A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10,
'K' => 11, 'L' => 12, 'M' => 13, 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19,
'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26
};
}
public void SetNumbers() {
Numbers = new Map<Integer, String> {1 => 'A', 2 => 'B', 3 => 'C', 4 => 'D', 5 => 'E'};
}
public String nextOne() {
if (InputArray[InputArray.size() - 1] != 'Z') {
Integer temp = Letters.get(InputArray[InputArray.size() - 1]);
InputArray[InputArray.size() - 1] = Numbers.get(temp + 1);
}
return String.fromCharArray(InputArray);
}
}
Upvotes: 2
Views: 8061
Reputation: 3585
Please look through the list of String static methods. You can find here that there is not such methods with signature String.fromCharArray(List<String> charArray)
but exist the next one String.fromCharArray(List<Integer> charArray)
/
Upvotes: 1
Reputation: 2983
So this turns out to be an issue of a bad compiler error message. What the issue was is that I wasn't using the correct signature for fromCharArray. It required a List of integers and I'm passing a List of String. In the long run I didn't want that method anyway. What helped me come to this conclusion was calling return System.String.fromCharArray(InputArray)
and it showed me that I may be using an incorrect signature for that method. Hope this helps others debug their Apex code.
Upvotes: 2