2013-03-25 7 views
5

से जावा पर कॉल करने का प्रयास कर रहा है, मैं सी ++ से जावा तक कॉल करना चाहता हूं। मैं एक फ़ंक्शन को कॉल करने का प्रयास करता हूं जो बिना किसी पैरामीटर के बूल वैल्यू को रीटंट करता है।जेएनआई रिटर्न सिग्नल 7 फ़ंक्शन सी ++

यह मेरी सी ++ कोड

/** 
* 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; 
} 

है और मेरे जावा कोड:

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; 
    } 
} 

लेकिन मैं मिलता है:

Fatal signal 7 (SIGBUS) at 0x00000000 (code=128) 

और मेरे पास है मैं एक वापसी मान सही ढंग से प्राप्त कर सकते हैं , मैं न तो पैरामीटर भेजने में सक्षम होगा।

+1

आप एक बूलियन लौट रहे हैं जो वास्तव में एक वस्तु है। इसके बजाए एक बूलियन आदिम प्रकार वापस करने का प्रयास करें। – maba

+0

मैंने जावा में एक बूलियन वैर जोड़ने की कोशिश की है लेकिन – vgonisanz

+0

वह लाइन जो असफल है "मध्य = env-> GetStaticMethodID (mClass," isInternetConnection ","() Z ");" अगर मैं उस पर टिप्पणी करता हूं, और निम्नलिखित यदि सिग्नल – vgonisanz

उत्तर

3

आप एक बूलियन लौट रहे हैं जो वास्तव में एक वस्तु है। इसके बजाए एक बूलियन आदिम प्रकार वापस करने का प्रयास करें।

0

क्या आप सुनिश्चित हैं कि FindClass NULL वापस नहीं आया? आप इसकी जांच नहीं कर रहे हैं

संबंधित मुद्दे