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
Pradeep Joshi 7Pradeep Joshi 7 

Method does not exist or incorrect signature: void generateStringArray(Integer) from the type StringArrayTest

Hi,
i am getting error while solving trailhead challange. please find below error.

"Method does not exist or incorrect signature: void generateStringArray(Integer) from the type StringArrayTest"

I tried some code given as best answers.

1. First Code I tried
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;
}
}

2. Second Code I tried
public class StringArrayTest {
public static List<String> generateStringArray(Integer n) {
List<String> List1 = new List<String>();
for(Integer i =0; i < n; ++i)
List1.add('Test ' + i);
return List1;
}
}

I am executing this code from DEBUG > Open Execute Anonymous Window and writing below code to call method.

StringArrayTest.generateStringArray(5);

Please suggest, How can I fix this

Thanks
Pradeep
Best Answer chosen by Pradeep Joshi 7
Deepali KulshresthaDeepali Kulshrestha
Hi Pradeep,
Greetings to you!

- I read your problem and implemented in my Org. Please use the below Execute Anonymous and class [ Solved]: -
 
Class : -
    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;
        }
    }

Execute Anonymous : -

    List<String> values=StringArrayTest.generateStringArray(5);
    System.debug('values-->'+values);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.

All Answers

Deepali KulshresthaDeepali Kulshrestha
Hi Pradeep,
Greetings to you!

- I read your problem and implemented in my Org. Please use the below Execute Anonymous and class [ Solved]: -
 
Class : -
    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;
        }
    }

Execute Anonymous : -

    List<String> values=StringArrayTest.generateStringArray(5);
    System.debug('values-->'+values);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
This was selected as the best answer
Pradeep Joshi 7Pradeep Joshi 7
Hi Deepali,
I have impelemented your code but giving same error.
Please find below screen shot.

Create apex class and execute codeExecution error message

I have also changed my trailhead playground but the same error is coming. please advise.

Thanks
Pradeep
 
Deepali KulshresthaDeepali Kulshrestha
Hi Pradeep,
Greetings to you!

- Your class is not saved after changes. please first save the apex class using 'Ctrl+s'.
- Then use 'Execute Anonymous'.
- Please find below screenshot for correction.

User-added image



I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.
Pradeep Joshi 7Pradeep Joshi 7
Thanks Deepali for your help.
It is working fine now. :)

Thanks & Regards
Pradeep