Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Android crashing on JNI CallStaticObjectMethod

user10784680Jan 1 2013 — edited Jan 2 2013
Hello there,

I'm trying to invoke a static method on Android and my app is crashing... the code is very simple, I ran out of ideas -- there isn't much I can think of that might be going on.

Here's the snippet:

char const *FileUtils::cachesDir() {
JavaVM *vm = JniHelper::getJavaVM();
JNIEnv *env;
int status = vm->GetEnv((void **)&env, JNI_VERSION_1_4);
if(status >= 0){
jclass cls = env->FindClass("android/content/ContextWrapper");
jmethodID method = env->GetMethodID(cls, "getFilesDir", "()Ljava/io/File;");
jobject result = env->CallStaticObjectMethod(cls, method, NULL); **// <-- ***** CRASHES WITH java.lang.NullPointerException at android.content.ContextWrapper.getFilesDir(ContextWrapper.java:193) *****
return "Found a result";
}
return "NULL";
}

Thougts?

Thanks and regards,
- Fabiano

Edited by: user10784680 on Jan 1, 2013 7:06 AM

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 30 2013
Added on Jan 1 2013
8 comments
9,497 views