Andrew
Andrew

Reputation: 89

How to cast WCHAR_T* to jstring?

I'm getting app crash when i try to pass WCHAR_T* to java method.

I have WCHAR_T* variable and it length.

I down know how to cast it to jstring to call java method.

my c++ code :

bool test(WCHAR_T* document){
    JNIEnv* jenv = getJniEnv();
    methodID_test = jenv->GetMethodID(cc, "test", "(Ljava/lang/String;)Z");
    return (bool)(jenv->CallBooleanMethod(obj,methodID_printDocument,document));
}

my java code :

public boolean test(String document) {
    return false;
}

Upvotes: 2

Views: 731

Answers (1)

SolidMercury
SolidMercury

Reputation: 1023

Use the NewString function to convert wchar_t to jstring.

jstring NewString(JNIEnv *env, const jchar *unicodeChars,  jsize len);

Upvotes: 1

Related Questions