public void Call(string methodName, params object[] args); 我想将字符串数组发送到我的项目中:string[] strings = new string[] { "string1", "string2", ...};myAndroidJavaObject.Call("myMethod", strings);并将其接收到Java代码中:public void myMethod(String[] strings){ // some code where I use strings}但是我收到错误消息: AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name='myMethod' signature='(Ljava/lang/String;Ljava/lang/String;)V' in class Ljava.lang.Object; 在这种情况下,谁能描述程序的行为?解决方案将数组发送到AndroidJavaObject时需要特殊处理.取自本文,您可以实现可以像这样处理它的功能:private AndroidJavaObject javaArrayFromCS(string [] values) { AndroidJavaClass arrayClass = new AndroidJavaClass("java.lang.reflect.Array"); AndroidJavaObject arrayObject = arrayClass.CallStatic<AndroidJavaObject>("newInstance", new AndroidJavaClass("java.lang.String"), values.Count()); for (int i=0; i<values.Count(); ++i) { arrayClass.CallStatic("set", arrayObject, i, new AndroidJavaObject("java.lang.String", values[i]))); } return arrayObject;}然后您可以像这样调用函数:myAndroidJavaObject.Call("myMethod", javaArrayFromCS(strings));I'm working on Unity for Android application, which uses native Android plugin. Inside of it I use AndroidJavaObject's Call method.As it says in documentation, signature of method is:public void Call(string methodName, params object[] args);I want to send array of strings into my project: string[] strings = new string[] { "string1", "string2", ...};myAndroidJavaObject.Call("myMethod", strings);And receive it into Java code:public void myMethod(String[] strings){ // some code where I use strings}But I receive error:AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name='myMethod' signature='(Ljava/lang/String;Ljava/lang/String;)V' in class Ljava.lang.Object;Can anyone describe program's behavior in this situation? 解决方案 Arrays require special treatment when being sent to an AndroidJavaObject. Taken from this article, you can implement a function that will handle it like so:private AndroidJavaObject javaArrayFromCS(string [] values) { AndroidJavaClass arrayClass = new AndroidJavaClass("java.lang.reflect.Array"); AndroidJavaObject arrayObject = arrayClass.CallStatic<AndroidJavaObject>("newInstance", new AndroidJavaClass("java.lang.String"), values.Count()); for (int i=0; i<values.Count(); ++i) { arrayClass.CallStatic("set", arrayObject, i, new AndroidJavaObject("java.lang.String", values[i]))); } return arrayObject;}You can then call into your function like this:myAndroidJavaObject.Call("myMethod", javaArrayFromCS(strings)); 这篇关于AndroidJavaObject.Call数组传递错误(适用于Android的Unity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 09:45