我想为我的 android 插件将数据从 Unity 发送到 java。
这是我的统一代码:
AndroidJNI.AttachCurrentThread();
IntPtr cls_Activity = AndroidJNI.FindClass("com/unity3d/player/UnityPlayer");
IntPtr fid_Activity = AndroidJNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;");
IntPtr obj_Activity = AndroidJNI.GetStaticObjectField(cls_Activity, fid_Activity);
Debug.Log("Setup Objects Complete");
IntPtr cls_OurAppNameActivityClass = AndroidJNI.FindClass("org/plugin/test/AdmobTestActivity");
IntPtr startAdsMethod = AndroidJNI.GetMethodID(cls_OurAppNameActivityClass, "EnableAds", "(J)V");
Debug.Log("before If Loop");
if (AndroidJNI.IsInstanceOf(obj_Activity, cls_OurAppNameActivityClass) != false)
{
//Debug.Log("Activity IS a OurAppNameActivity");
jvalue[] myArray = new jvalue[1];
myArray[0] = new jvalue();
myArray[0].i = 12;
AndroidJNI.CallVoidMethod(obj_Activity, startAdsMethod, myArray);
Debug.Log("Activity Leaving a OurAppNameActivity");
}
这是我的 Java 代码:
public void EnableAds(int qwe)
{
Log.i(APP_TAG, "Value" + qwe);
}
错误:
05-16 13:11:30.906: W/dalvikvm(12315): threadid=8: thread exiting with uncaught exception (group=0x40018578)
05-16 13:11:30.921: E/AndroidRuntime(12315): FATAL EXCEPTION: GLThread 9
05-16 13:11:30.921: E/AndroidRuntime(12315): java.lang.NoSuchMethodError: EnableAds
05-16 13:11:30.921: E/AndroidRuntime(12315): at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
05-16 13:11:30.921: E/AndroidRuntime(12315): at com.unity3d.player.UnityPlayer.onDrawFrame(Unknown Source)
05-16 13:11:30.921: E/AndroidRuntime(12315): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1368)
05-16 13:11:30.921: E/AndroidRuntime(12315): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1123)
并强制关闭..
如果我在 java 代码中从 EnableAdv(int qwe) 中删除了 int 参数,则此应用程序工作正常。
谁能告诉我,这段代码中缺少什么。?