简体   繁体   中英

Creating a list of java strings in Unity C#

I need to create a java list of java.lang.String in order to pass it to a method (for facebook sharing).

public E setPeopleIds(java.util.List<java.lang.String> peopleIds)

and this is how I call it

shareLinkContentBuilder.Call<AndroidJavaObject>("setPeopleIds", ToJavaList(facebookID));

I can't figure out how to create a list of java strings from c# strings. This is what I've tried but I get a nre exception on the list.Call line

private AndroidJavaObject ToJavaList(string value)
    {
        AndroidJavaObject list = new AndroidJavaObject("java.util.List");
        list.Call("add", new AndroidJavaObject("java.lang.String", value));
        return list;
    }

Can't find any info as most of the topics are on xamarin or they are using arrays instead of lists.

It could be that java.util.List is an interface and therefore cannot support methods like add by itself. You might have to use an implementation of a java list, like java.util.ArrayList

Another thing is that the latter function is creating a new list every time with only one element. I'm not sure if that's what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM