0
我有以下JNI函數將事件發送到我的Java代碼。導致Android應用崩潰的JNI函數
void onIncrementAchievement(unsigned char _iArgumentCount, const void *_pArguments, void *_pUserData){
JNIEnv *pJNIEnv = GetJNIEnv();
if (pJNIEnv){
if (_pArguments && (_iArgumentCount > 0)){
const S3DX::AIVariable *pVariables = (const S3DX::AIVariable *)_pArguments ;
if(_iArgumentCount != 2)
LOGI("INCORRECT NUMBER OF PARAMETERS");
else{
if(pVariables[0].GetType() == S3DX::AIVariable::eTypeString){
// CHANGE ME!
jclass pJNIActivityClass = pJNIEnv->FindClass ("com/nurfacegames/testgame01/TestGame01");
if(pJNIActivityClass == NULL)
LOGI("jclass was null!?!");
else{
jmethodID pJNIMethodID = pJNIEnv->GetStaticMethodID(pJNIActivityClass, "onIncrementAchievement", "(Ljava/lang/String;Ljava/lang/Integer;)V");
if(pJNIMethodID == NULL)
LOGI("jmethodID was null!?!?");
else{
//Create a new string
jstring arg;
arg = pJNIEnv->NewStringUTF(pVariables[0].GetStringValue());
jint arg2 = pVariables[1].GetNumberValue();
//Call the method and pass the string parameter along
pJNIEnv->CallStaticVoidMethod(pJNIActivityClass, pJNIMethodID, arg, arg2);
//Free the string
pJNIEnv->DeleteLocalRef(arg);
}
}
}
}
}
}
}
當我運行我的Android應用程序,它強制關閉,甚至沒有在logcat中給人一個錯誤,當我用Ant編譯,沒有編譯錯誤。
我討厭發佈這樣一個模糊的問題,但如果有人有一個想法我的JNI代碼有什麼問題,請給我一個提示。謝謝!
,我認爲有一個問題(我一直在努力)的領域有:
if(_iArgumentCount != 2)
LOGI("INCORRECT NUMBER OF PARAMETERS");
else{
和本節:
jint arg2 = pVariables[1].GetNumberValue();
pJNIEnv->CallStaticVoidMethod(pJNIActivityClass, pJNIMethodID, arg, arg2);
謝謝!