+ Start a Discussion
Deepika GhoseDeepika Ghose 

Getting this error in challenge:

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.

My code is:
public class StringArrayTest {
    
    public static List<String> generateStringArray(Integer l)
    {
     List<String> a1=new List<String>();
        for(i=0;i<l;i++)
        {
            a1.add('Test '+i);
            System.debug(a1[i]);
        }
        return a1;
    }


m executing through
StringArrayTest em = new StringArrayTest();
em.generateStringArray(5);

Can anyone help me whats wrong I did here?
Ajay mishraAjay mishra
Hi Deepika,

Can you share challenge description.

Regards,
Ajay Mishra
Email: mishraajay.m1@gmail.com
sfdcMonkey.comsfdcMonkey.com
hi Deepika Ghose 

try below code 
 
public class StringArrayTest { 
   public static List<String> generateStringArray(Integer n) { 
    List<String> myArray = new List<String>(); 
     for(Integer i=0;i<n;i++) {
       myArray.add('Test '+i); 
       System.debug(myArray[i]); } 
        return myArray; 
    }
 }

Thanks 
Mark it best answer if it helps you :)
Ajay mishraAjay mishra
Hey Deepika,

As mention in Challenge String should be returned in this format 'Test n'.

You are missing the spcae in between them. Please add a space in front of 'Test'.

Your Challenge will be completed.

Regards,
Ajay Mishra
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000BTQ9IAO

Problem in your code is that you need to pass one space between 'Test '+i and you need to start loop from zero

Please try below code:-
public class StringArrayTest {
        public static String[] generateStringArray(Integer length) {
        String[] myArray = new List<String>();
        for(Integer i=0;i<length;i++) {
           myArray.add('Test ' + i);

            System.debug(myArray[i]);
        } 
        return myArray;
    }     
}
And go :
Your Name>Developer Console>Debug>Open Execute Anonymous Window 
Paste below code in it
list<string> myArray = StringArrayTest.generateStringArray(10);
system.debug('************'+myArray);
Please let us know if this will help you