I am getting a error while returning a list?

i am getting a error while returning a list ??

how to return a list ??

my code

two variables -

public String[] Strr;
public String[] pkgList;

code in

    String[] Strr = new String[] {ExampleList};
          this.Strr = Strr;

return Strr;

Sur, @hammerhai kindly take a look.

Hello @AryanGupta,

I am glad you felt the need to mention me in the first post, however with other people it can be a burden to them. Please do not mention someone in the first post again.

To return a list you would actually do…

/** Do not use a wildcard for the YailList (such as com.google.appinventor.components.runtime.util.*), instead reference the class otherwise it will not work **/
import com.google.appinventor.components.runtime.util.YailList;

public YailList ReturnListExample() {
  YailList myList = new YailList();

  return myList;

If doing myList.addItem("String") on that example gives you an error, then do the following instead…

import java.util.ArrayList;
import java.util.List;

public List ReturnListExample() {
  List myList = new ArrayList();

  return myList;

Now if the previous example didn’t work (which it should as from the code from my extensions source), the last try would be…

import java.util.ArrayList;

public ArrayList ReturnListExample() {
  ArrayList myList = new ArrayList();

  return myList;

But, try the first 2 examples and see where you get before resorting to the final solution!

1 Like

can i use a Variable Like this.list instead of (“String”)

public ArrayList PackageNames() {

return ExampleList;

not working ??

i want to say that i don’t want to create any ArrayList. because i have already a list named ExampleList.

now, i wanted to return this ExampleList list.

@hammerhai please help

Ok let me rephrase the question so that I understand better, and you tell me if it’s correct.

You have an ArrayList, but you want to return it as a YailList?

i have a ArrayList And i want to return ArrayList;

but it saying unable to convert String to String.

Can you show me what you have as your ExampleList variable? Like what does it equal?

EDIT: I have to go to sleep so I will help you when I wake up.

i don’t know what is in it ??
because i am getting a unKnown Value

Wake Up bru :wink:

i just created YailList But i still getting a error

error: YailList(Object) has private access in YailList
    [javac] return new YailList(myList);

@Mohamed_Tamer Sur, kindly take a look

I just don’t understand why you would want to return ArrayList, because Kodular (AI2) won’t be able to cast it for you.

To convert ArrayList to YailList, do

1 Like

what are you saying ??

1 Like

and BTW, i i have ArrayList . so, i am converting it to YailList.

Yes, if you can kindly read my post:

1 Like

how can i return it ??

return YailList.makeList(ArrayList);

Remember the type you’re returning is YailList, so the top should be like this:

@SimpleFunction(description = "")
public YailList YourMethod() {...}
1 Like

let me try

Thank you for doing that @WatermelonIce :sweat_smile: I didn’t wake up til a few minutes ago!