问题描述:

I 'm getting a SIGNAL 11 in this line:

// Call bool isInternetConnection()

jboolean jReturnValue = env->CallBooleanMethod(mClass,mid);

in this piece of code:

/**

* Check if Internet Connection is ONLINE

*/

bool InterfaceJNI::isInternetConnected()

{

JavaVM* jvm = JniHelper::getJavaVM();

int status;

JNIEnv *env;

jmethodID mid;

bool isAttached = false;

bool returnValue = false;

CCLog("InterfaceJNI isInternetConnected");

// Get Status

status = jvm->GetEnv((void **) &env, JNI_VERSION_1_6);

if(status < 0)

{

CCLog("isInternetConnected Status < 0 Failed to get JNI Enviroment!!!");

status = jvm->AttachCurrentThread(&env, NULL);

CCLog("isInternetConnected Status 2: %d", status);

if(status < 0)

{

CCLog("isInternetConnected Status < 0 !!!");

return false;

}

isAttached = true;

CCLog("isInternetConnected Status isAttached: %d", isAttached);

}

CCLog("isInternetConnected Status: %d", status);

CCLog("isInternetConnected Finding Class....");

jclass mClass = env->FindClass("org/example/SocialNetwork/CCSocialNetwork");

// Get Static bool isInternetConnection()

CCLog("isInternetConnected Getting method....");

mid = env->GetMethodID(mClass, "isInternetConnection", "()Z");

if (mid == 0)

{

CCLog("isInternetConnected FAIL GET METHOD STATIC");

return false;

}

CCLog("isInternetConnected Calling method....");

// Call bool isInternetConnection()

jboolean jReturnValue = env->CallBooleanMethod(mClass,mid);

CCLog("Call done ");

// Convert value from Java to C++

returnValue = (bool)jReturnValue;

CCLog("isInternetConnected Done ");

if(isAttached)

jvm->DetachCurrentThread();

// Change for return value

return returnValue;

}

But I don't know why. If I make a void call with a "()V" works fine, but when I try to call a function which return a bool no.

What is going on?

网友答案:

Is it a static method or not? Your comments in the code indicate that it is static while your method calls do not.

If it is NOT static then you will have to call the CallBooleanMethod with an object and not the class like you do now. Otherwise you will have to use CallStaticBooleanMethod with the class.

jobject someObject = <get or create the object somehow>
jboolean jReturnValue = env->CallBooleanMethod(someObject,mid);

OR

jboolean jReturnValue = env->CallStaticBooleanMethod(mClass,mid);

Either way you will have to decide whether to use static methods or not.

相关阅读:
Top