文章撰寫日期︰2013/07/17 11:42 cocos2dx使用版本︰v 2.0.4
cocosBuilder使用版本︰v 2.0 alpha 1
一、問題
今天在寫JNI試圖從C++ call JAVA時,遇到了
Fatal signal 11 (SIGSEGV) xxxx
的問題,
告訴我找不到JAVA層的某個static函式。
二、解決辦法
JAVA端的Code如下
package com.simon.utility;
public class DataManager {
public static void test(){
Log.i("tag", "into test");
}
}
C++端使用JNI呼叫上面的Java函式
void FileOperator::getAndroidTest(){
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
CCLog("into FileOperator::getAndroidTest(), Involking JNI...");
JniMethodInfo t;
if (JniHelper::getStaticMethodInfo(t, "com/simon/utility/DataManager","test","()V;"))
{
CCLog("classID: %d",t.classID);
CCLog("methodID: %d",t.methodID);
t.env->CallStaticBooleanMethod(t.classID,t.methodID);
}
#endif
}
程式一直跟我報找不到test這個函式,後來才知道()V;那邊
V後面不用打分號!
題外話︰
()是JAVA端接收參數的值
V是這隻JAVA函式是否有回傳值。
