You need to sign in to do that
Don't have an account?

What's wrong in Trailhead Apex class exercise 1?
Hi,
I tried writing the sample apex class to return list of strings. Below is the code and when I check the challenge - I get the error as "Challenge not yet complete... here's what's wrong: Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.". What's wrong in the code?
public class StringArrayTest {
public static List<String> generateStringArray(Integer len) {
Integer inp = len;
List <String> Arrlist = new List<String>();
for(Integer i=0; i < len; i++){
Arrlist.add('Test: ' + i);
system.debug(Arrlist.get(i));
// system.debug('len value: ' + inp);
}
return Arrlist;
}
}
I tried writing the sample apex class to return list of strings. Below is the code and when I check the challenge - I get the error as "Challenge not yet complete... here's what's wrong: Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.". What's wrong in the code?
public class StringArrayTest {
public static List<String> generateStringArray(Integer len) {
Integer inp = len;
List <String> Arrlist = new List<String>();
for(Integer i=0; i < len; i++){
Arrlist.add('Test: ' + i);
system.debug(Arrlist.get(i));
// system.debug('len value: ' + inp);
}
return Arrlist;
}
}
you should have this.
Arrlist.add('Test ' + i);
All Answers
you should have this.
Arrlist.add('Test ' + i);