call a static JNI method to return a String from C++

Viewed 7355

I am trying to call the following java method in Android

public static String getLevelFile(String levelName) { /*body*/}

from c++ using the following jni code

JniMethodInfoJavaApi methodInfo;

    if (! getStaticMethodInfo(methodInfo, "getLevelFile", "(Ljava/lang/String;)Ljava/lang/String;"))
        {
            return std::string("");
        }
    LOGD("calling getLevelFile");
    jstring returnString = (jstring) methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID, levelName.c_str());
    LOGD("returned from getLevelFile");
    methodInfo.env->DeleteLocalRef(methodInfo.classID);

    const char *js = methodInfo.env->GetStringUTFChars(returnString, NULL);
    std::string cs(js);
    methodInfo.env->ReleaseStringUTFChars(returnString, js);
    LOGD("returning Level data");

The app crashes when doing the CallStaticMethodObject() . I have verified that the method signature is correct by using javap. And the LOGD("calling getLevelFile"); prints fine and then it crashes. I am able to do other CallStaticVoidMethod()s from the same class but not this one. Any ideas what I am doing wrong?

2 Answers
Related