I want to make a call from C ++ to Java. I am trying to call a function that returns a bool value without parameters.
This is my C ++ code
bool InterfaceJNI::isInternetConnected()
{
JavaVM* jvm = JniHelper::getJavaVM();
int status;
JNIEnv *env;
jmethodID mid;
bool isAttached = false;
bool returnValue = false;
CCLog("Static isInternetConnected");
status = jvm->GetEnv((void **) &env, JNI_VERSION_1_6);
if(status < 0)
{
status = jvm->AttachCurrentThread(&env, NULL);
CCLog("isInternetConnected Status 2: %d", status);
if(status < 0)
{
return false;
}
isAttached = true;
CCLog("isInternetConnected Status isAttached: %d", isAttached);
}
CCLog("isInternetConnected Status: %d", status);
jclass mClass = env->FindClass("org/example/SocialNetwork/InternetConnection");
mid = env->GetStaticMethodID(mClass, "isInternetConnection", "()Z");
if (mid == 0)
{
CCLog("isInternetConnected FAIL GET METHOD STATIC");
return false;
}
returnValue = env->CallStaticBooleanMethod(mClass, mid);
CCLog("isInternetConnected Done ");
CCLog("Finish");
if(isAttached)
jvm->DetachCurrentThread();
return returnValue;
}
And my Java code:
public class InternetConnection
{
public static void helloWorld()
{
Log.v("InternetConnection", "HELLO WORLD");
}
public static Boolean isInternetConnection()
{
Log.v("InternetConnection", "isInternetConnection Start");
Context ctx = CCSocialNetwork.getAppContext();
ConnectivityManager conMgr = (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo i = conMgr.getActiveNetworkInfo();
if (i == null)
{
Log.v("InternetConnection", "isInternetConnection NULL :S");
return false;
}
if (!i.isConnected())
{
Log.v("InternetConnection", "isInternetConnection is not connected");
return false;
}
if (!i.isAvailable())
{
Log.v("InternetConnection", "isInternetConnection is not available");
return false;
}
Log.v("InternetConnection", "isInternetConnection DONE!");
return true;
}
}
But I get:
Fatal signal 7 (SIGBUS) at 0x00000000 (code=128)
And I have If I can get the return value correctly, I would not be able to send the parameters.
source
share