简体   繁体   English

在 Unity C# 中创建 Java 字符串列表

[英]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).我需要创建一个 java.lang.String 的 java 列表,以便将它传递给一个方法(用于 facebook 共享)。

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.我不知道如何从 c# 字符串创建 java 字符串列表。 This is what I've tried but I get a nre exception on the list.Call line这是我尝试过的,但我在 list.Call 行上遇到了 nre 异常

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.找不到任何信息,因为大多数主题都在 xamarin 上,或者他们使用的是数组而不是列表。

It could be that java.util.List is an interface and therefore cannot support methods like add by itself.可能是java.util.List是一个接口,因此不能单独支持add的方法。 You might have to use an implementation of a java list, like java.util.ArrayList您可能必须使用 java 列表的实现,例如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.我不确定这是否是你想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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