调用CallVoidMethod时的NoSuchMethodError

时间:2013-01-07 05:58:22

标签: java c++ java-native-interface nosuchmethoderror jnienv

我从我的jni类调用非静态函数,但我的游戏得到了

  

的NoSuchMethodError

我已经给出了以下功能

jni class

void InitializeJni()
{
    cocos2d::JniMethodInfo methodInfo;
    if (! JniHelper::getStaticMethodInfo(methodInfo, CLASS_NAME, "Start", "()V"))
    {
        return ;
    }
    methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID);
    methodInfo.env->DeleteLocalRef(methodInfo.classID);
}

JNIEXPORT void JNICALL Java_com_games_Game_MyClass_nativeObjectCallBack(JNIEnv *env, jobject obj)
{
    jclass cls = env->GetObjectClass(obj);
    jmethodID mid = env->GetMethodID(cls, "Init", "()V");
    if (mid == 0)
        return;
    env->CallVoidMethod(obj, mid);

Java类

public static native void nativeObjectCallBack();

public void Init()
{
    //my code
}

public static void Start()
{
    ((CYWGameAndroid)CYWUtil.GetInstance().GetContext()).runOnUiThread(new Runnable()
    {
        @Override
        public void run() 
        {
            nativeObjectCallBack();
        }
    });
}

任何人都可以告诉我为什么会这样

这是我的logcat输出

01-07 16:53:49.987: D/dalvikvm(11832): GetMethodID: method not found: Ljava/lang/Class;.Init:()V
01-07 16:53:52.049: D/AndroidRuntime(11832): Shutting down VM
01-07 16:53:52.049: W/dalvikvm(11832): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
01-07 16:53:52.109: E/AndroidRuntime(11832): FATAL EXCEPTION: main
01-07 16:53:52.109: E/AndroidRuntime(11832): java.lang.NoSuchMethodError: Init
01-07 16:53:52.109: E/AndroidRuntime(11832):    at com.games.Game.MyClass.nativeObjectCallBack(Native Method)

0 个答案:

没有答案