It makes me cry. JNI is a necessary evil, but still evil.
Why isn't there some nice way to call a CallStringMethod? Especially when working with
Android's bundles, which have getString. It would make life a million times easier.
Anyway here's a workaround:
jstring my_java_string = (jstring)env->CallObjectMethod(bundle, myBundle.getString, env->NewStringUTF("test"));
if(my_java_string
== NULL){
// Error
return;
}
char*my_c_string
= strdup(env->GetStringUTFChars(
my_java_string
, 0));
env->ReleaseStringUTFChars(my_java_string
,
my_c_string
);
A blog about computer and electronics projects to make life just that little bit sweeter.
Wednesday, October 6, 2010
JNI - where's the env->CallStringMethod?
Labels:
Android,
C,
GetStringMethod,
Java,
JNI
Subscribe to:
Post Comments (Atom)
It worked, thank you!
ReplyDeleteI think you're passing the wrong parameter to ReleaseStringUTFChars. You shouldn't be passing my_c_string, as that was returned from strdup. Instead you should pass the return value from the GetStringUTFChars call.
ReplyDelete