我正在尝试将一些数据(从 java 类获得)设置为 CCDictionary,然后将该字典对象添加到 c++ 类中的 CCArray 中,如下所示。addFriends(...) 是从本地方法调用的。
void RecJNICommunicator::addFriends(const char * nativeStringUserName, const char * nativeStringUserId) {
CCLog(" --- inside RecJNICommunicator::addFriends --- ");
CCDictionary * cdictionary = CCDictionary::create();
CCString *str1 = CCString::create(nativeStringUserName);
CCString *str2 = CCString::create(nativeStringUserId);
cdictionary->setObject(str1, "name");
cdictionary->setObject(str2, "id");
if(!FacebookFriendListScreen::friendsList) {
CCLog(" --- FacebookFriendListScreen::friendsList is NULL... creating new --- ");
FacebookFriendListScreen::friendsList = new CCArray;
}
// 将字典对象添加到 CCArray
FacebookFriendListScreen::friendsList->addObject(cdictionary);
CCLog(" --- added successfully --- ");
}
第一次成功添加,但后来应用程序崩溃并出现以下堆栈跟踪
12-11 10:21:39.707: INFO/DEBUG(24299): #00 pc 001363d2
/data/data/com.humit/lib/libgame.so (_ZN7cocos2d12CCDictionary15setObjectUnSafeEPNS_8CCObjectERKSs)
12-11 10:21:39.707: INFO/DEBUG(24299): #01 pc 00135258 /data/data/com.humit/lib/libgame.so (_ZN7cocos2d12CCDictionary9setObjectEPNS_8CCObjectERKSs)
12-11 10:21:39.707: INFO/DEBUG(24299): #02 pc 000f2d9a /data/data/com.humit/lib/libgame.so (_ZN18RecJNICommunicator10addFriendsEPKcS1_)
12-11 10:21:39.707: INFO/DEBUG(24299): #03 pc 000f2c42 /data/data/com.humit/lib/libgame.so (Java_com_humit_android_HumIt_addFriends)
12-11 10:21:39.707: INFO/DEBUG(24299): #04 pc 0001ed70 /system/lib/libdvm.so (dvmPlatformInvoke)
12-11 10:21:39.707: INFO/DEBUG(24299): #05 pc 0005902c /system/lib/libdvm.so (_Z16dvmCallJNIMethodPKjP6JValuePK6MethodP6Thread)
12-11 10:21:39.712: INFO/DEBUG(24299): #06 pc 0005ad5c /system/lib/libdvm.so (_Z22dvmResolveNativeMethodPKjP6JValuePK6MethodP6Thread)
12-11 10:21:39.712: INFO/DEBUG(24299): #07 pc 00030bcc /system/lib/libdvm.so
12-11 10:21:39.712: INFO/DEBUG(24299): #08 pc 000343b0 /system/lib/libdvm.so (_Z12dvmInterpretP6ThreadPK6MethodP6JValue)
12-11 10:21:39.712: INFO/DEBUG(24299): #09 pc 0006c8c6 /system/lib/libdvm.so (_Z15dvmInvokeMethodP6ObjectPK6MethodP11ArrayObjectS5_P11ClassObjectb)
12-11 10:21:39.712: INFO/DEBUG(24299): #10 pc 00073eba /system/lib/libdvm.so
12-11 10:21:39.712: INFO/DEBUG(24299): #11 pc 00030bcc /system/lib/libdvm.so
12-11 10:21:39.712: INFO/DEBUG(24299): #12 pc 000343b0 /system/lib/libdvm.so (_Z12dvmInterpretP6ThreadPK6MethodP6JValue)
12-11 10:21:39.712: INFO/DEBUG(24299): #13 pc 0006cb96 /system/lib/libdvm.so (_Z14dvmCallMethodVP6ThreadPK6MethodP6ObjectbP6JValueSt9__va_list)
12-11 10:21:39.712: INFO/DEBUG(24299): #14 pc 00054ff6 /system/lib/libdvm.so
12-11 10:21:39.717: INFO/DEBUG(24299): #15 pc 00049d8a /system/lib/libandroid_runtime.so
12-11 10:21:39.717: INFO/DEBUG(24299): #16 pc 0004b68e /system/lib/libandroid_runtime.so (_ZN7android14AndroidRuntime5startEPKcS2_)
12-11 10:21:39.717: INFO/DEBUG(24299): #17 pc 00008f0a /system/bin/app_process
12-11 10:21:39.717: INFO/DEBUG(24299): #18 pc 0001685c /system/lib/libc.so (__libc_init)
我对 C++ 编程很陌生,所以我做错了什么?谢谢。