JNI returns the signal 7 function and tries to call Java from C
•
Java
I want to make a call from C to Java I try to call a function to invert a bool value without parameters
This is my C code
/** * Check if Internet Connection is ONLINE */ bool InterfaceJNI::isInternetConnected() { JavaVM* jvm = JniHelper::getJavaVM(); int status; jnienv *env; jmethodID mid; bool isAttached = false; // jboolean o bool? bool returnValue = false; CCLog("Static isInternetConnected"); // Get Status status = jvm->GetEnv((void **) &env,JNI_VERSION_1_6); if(status < 0) { //LOGE("callback_handler: Failed to get JNI environment," // "assuming native thread"); status = jvm->AttachCurrentThread(&env,NULL); CCLog("isInternetConnected Status 2: %d",status); if(status < 0) { // LOGE("callback_handler: Failed to attach " // "current thread"); return false; } isAttached = true; CCLog("isInternetConnected Status isAttached: %d",isAttached); } CCLog("isInternetConnected Status: %d",status); jclass mClass = env->FindClass("org/example/SocialNetwork/InternetConnection"); // Get Static bool isInternetConnection() mid = env->GetStaticMethodID(mClass,"isInternetConnection","()Z"); if (mid == 0) { CCLog("isInternetConnected FAIL GET METHOD STATIC"); return false; } // Call Static bool isInternetConnection() returnValue = env->CallStaticBooleanMethod(mClass,mid); CCLog("isInternetConnected Done "); //----------------------------------------------------------- CCLog("Finish"); if(isAttached) jvm->DetachCurrentThread(); // Change for return value return returnValue; }
My java code:
public class InternetConnection { /** * Check if is working your hello world from C++ */ public static void helloWorld() { Log.v("InternetConnection","HELLO WORLD"); } /** * Check Internet Connection * @return true is Online */ 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)
If I can get the return value correctly, I can't send parameters
Solution
You are returning a Boolean value that is actually an object An attempt was made to return a Boolean primitive type
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码