function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
animesh singhanimesh singh 

I am getting same problem even if my output is correct

public class StringArrayTest{
    public static List<String> generateStringArray(Integer n){
    List<String> lstString = new List<String>();
     for(Integer i=0; i<n;i++){
         lstString.add('\'Test '+i + '\'');        
     }
        System.debug('__________'+lstString);
        return lstString;
    }   
}
Best Answer chosen by animesh singh
Adam Purkiss 99Adam Purkiss 99
Have you tried adding a string without the extra single quotes? For example:
 
lstString.add('Test ' + i);



 

All Answers

Adam Purkiss 99Adam Purkiss 99
Have you tried adding a string without the extra single quotes? For example:
 
lstString.add('Test ' + i);



 
This was selected as the best answer
animesh singhanimesh singh
Yes Adam I have tried this one getting same error. 
animesh singhanimesh singh
Even I tried this also lstString.add('Test'+i );
Adam Purkiss 99Adam Purkiss 99
Your code looks fine. Can you post the exact error message you're seeing? Specifically, is there a reference number included, or is it just saying one of the following?:
 
No Apex class named 'StringArrayTest' was found

or

Executing the 'generateStringArray' method failed. Either the method does not exist, is not static, or does not return the proper number of strings.

 
animesh singhanimesh singh
Hi Adam I was getting all these messages which you have mentioned. But Now my error has resolved :) . I tried only lstString.add('Test ' + i); and It has passed.

Thanks for your help.
satya chikkala 3satya chikkala 3
Hi Adam,

I am facing similar issue and don't know where the problem is.

Error :
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.​


Code:
public class StringArrayTest {
public static list<string> generateStringArray(Integer i)
{
    List<String> myArray= new List<string>();
        for(Integer k=0;k<=i;k++)
    {
    myArray.add('Test '+k); 
     system.debug(myArray[k]);
     }
 return myArray;
}
}

The code is running fine when I run it.

Kindly help.

Regards,
Satya
Jason FungJason Fung
@satya The return type of your generateStringArray(Integer i) method should be String[]

Please change your method to public static String[] generateStringArray(Integer i)  { ... } and see if that works.
Johnny Morris 1Johnny Morris 1
I have the same problem, here is my code
 
public class StringArrayTest {
    
    public static List<String> generateStringArray(Integer n) {
        
        List<String> textList = new List<String>();

        for (Integer i = 0; i <= n; i++) {
            String testStringFormat = 'Test ' + i;
            
            textList.add(testFormat);
        }
        system.debug(textList);
        return textList;
    }
	
}


 
Arunkumar Pandyan RamarArunkumar Pandyan Ramar
I too get the following error message

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 as shown below.

public class StringArrayTest {
    
    public static List<String> generateStringArray(Integer n){
        List<String> str = new List<String>(n);
        for(Integer j=0;j<n ;j++){
           str.add('Test '+String.valueOf(j));
          }
        return str ;
    }
}

When I test this on the debug-->open  execute anonymous window,

with the following code, it runs successfully.

List<String> ls = StringArrayTest.generateStringArray(10);
for (Integer m=0;m<10;m++){
    System.debug(ls[m]);
}

 
Samata Doshi - ExtentiaSamata Doshi - Extentia
@Arunkumar Pandyan Ramar,
Try removing n from this statement:  List<String> str = new List<String>(n);
It should work.