Cocos2dx Android:getFileData无法从资产中获取.json文件

时间:2012-11-28 12:29:20

标签: android c++ json cocos2d-x assets

我正在开发Android和IOS的跨平台应用程序。当我尝试获取位于资产文件夹中的.json文件时,如下所示

const char * genrefile =   CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("genres.json");
CCLog( " %s ---------- genrefile ---------", genrefile);

size_t size;
unsigned char * charbuffer = CCFileUtils::sharedFileUtils()->getFileData(genrefile, "rb", 0);

控件来自应用程序,具有以下堆栈跟踪

11-28 16:53:51.319: INFO/DEBUG(13089): *** *** *** *** *** *** *** *** *** *** *** *** 

*** *** *** ***
11-28 16:53:51.319: INFO/DEBUG(13089): Build fingerprint: 'samsung/GT-P7300/GT-P7300:3.1/HMJ37/XWKI3:user/release-keys'
11-28 16:53:51.319: INFO/DEBUG(13089): pid: 13255, tid: 13263  >>> com.humit <<<
11-28 16:53:51.319: INFO/DEBUG(13089): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
11-28 16:53:51.319: INFO/DEBUG(13089):  r0 000c4780  r1 00218274  r2 00000000  r3 00000000
11-28 16:53:51.319: INFO/DEBUG(13089):  r4 80f80524  r5 00000000  r6 5c160c18  r7 52b1df2c
11-28 16:53:51.319: INFO/DEBUG(13089):  r8 5c160b70  r9 52b1df24  10 52b1df10  fp 00000000
11-28 16:53:51.319: INFO/DEBUG(13089):  ip afc03108  sp 5c160488  lr 80d5f981  pc 80d5f516  cpsr 40000030
11-28 16:53:51.319: INFO/DEBUG(13089):  d0  c449c9bc448522eb  d1  447a0000c425612c
11-28 16:53:51.319: INFO/DEBUG(13089):  d2  46fffe00c47a0000  d3  c1e00000ffffffe4
11-28 16:53:51.319: INFO/DEBUG(13089):  d4  c1dec600c1dac600  d5  4110000000000009
11-28 16:53:51.319: INFO/DEBUG(13089):  d6  3f800000ffffffe0  d7  4485261dbf800000
11-28 16:53:51.319: INFO/DEBUG(13089):  d8  0000000000000000  d9  0000000000000000
11-28 16:53:51.319: INFO/DEBUG(13089):  d10 0000000000000000  d11 0000000000000000
11-28 16:53:51.319: INFO/DEBUG(13089):  d12 0000000000000000  d13 0000000000000000
11-28 16:53:51.319: INFO/DEBUG(13089):  d14 0000000000000000  d15 0000000000000000
11-28 16:53:51.319: INFO/DEBUG(13089):  scr 60000012
11-28 16:53:51.409: DEBUG/Finsky(2593): [1] 5.onFinished: Installation state replication succeeded.
11-28 16:53:51.459: INFO/DEBUG(13089):          #00  pc 0015f516  /data/data/com.humit/lib/libgame.so (_ZN7cocos2d11CCFileUtils18getFileDataFromZipEPKcS2_Pm)
11-28 16:53:51.469: INFO/DEBUG(13089):          #01  pc 0015f97c  /data/data/com.humit/lib/libgame.so (_ZN7cocos2d11CCFileUtils11getFileDataEPKcS2_Pm)
11-28 16:53:51.469: INFO/DEBUG(13089):          #02  pc 000f0fe2  /data/data/com.humit/lib/libgame.so (_ZN17SelectGenreScreen9loadgenreEv)
11-28 16:53:51.469: INFO/DEBUG(13089):          #03  pc 000f11fa  /data/data/com.humit/lib/libgame.so (_ZN17SelectGenreScreen4initEv)
11-28 16:53:51.469: INFO/DEBUG(13089):          #04  pc 000f0934  /data/data/com.humit/lib/libgame.so (_ZN17SelectGenreScreen6createEv)
11-28 16:53:51.469: INFO/DEBUG(13089):          #05  pc 000f0b1c  /data/data/com.humit/lib/libgame.so (_ZN17SelectGenreScreen5sceneEv)
11-28 16:53:51.469: INFO/DEBUG(13089):          #06  pc 000f6c24  /data/data/com.humit/lib/libgame.so (_ZN18RandomPlayerScreen22onHttpRequestCompletedEPN7cocos2d6CCNodeEPv)
11-28 16:53:51.469: INFO/DEBUG(13089):          #07  pc 001bd1fa  /data/data/com.humit/lib/libgame.so (_ZN7cocos2d9extension12CCHttpClient25dispatchResponseCallbacksEf)
11-28 16:53:51.469: INFO/DEBUG(13089):          #08  pc 000f8a72  /data/data/com.humit/lib/libgame.so (_ZN7cocos2d7CCTimer6updateEf)
11-28 16:53:51.469: INFO/DEBUG(13089):          #09  pc 000fe49e  /data/data/com.humit/lib/libgame.so (_ZN7cocos2d11CCScheduler6updateEf)
11-28 16:53:51.469: INFO/DEBUG(13089):          #10  pc 001288c0  /data/data/com.humit/lib/libgame.so (_ZN7cocos2d10CCDirector9drawSceneEv)
11-28 16:53:51.469: INFO/DEBUG(13089):          #11  pc 00129ec0  /data/data/com.humit/lib/libgame.so (_ZN7cocos2d21CCDisplayLinkDirector8mainLoopEv)
11-28 16:53:51.469: INFO/DEBUG(13089):          #12  pc 00165a08  /data/data/com.humit/lib/libgame.so (Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeRender)
11-28 16:53:51.469: INFO/DEBUG(13089):          #13  pc 00011d34  /system/lib/libdvm.so
11-28 16:53:51.469: INFO/DEBUG(13089):          #14  pc 000411a2  /system/lib/libdvm.so (dvmCallJNIMethod_staticNoRef)
11-28 16:53:51.469: INFO/DEBUG(13089): libc base address: aff00000
11-28 16:53:51.469: INFO/DEBUG(13089): code around pc:
11-28 16:53:51.469: INFO/DEBUG(13089): 80d5f4f4 4c5b44a5 9007447c 92059106 4b599304 
11-28 16:53:51.469: INFO/DEBUG(13089): 80d5f504 681b58e3 230093a1 2300931f 9b04931e 
11-28 16:53:51.469: INFO/DEBUG(13089): 80d5f514 601a2200 2b009b06 e07dd100 2b009b05 
11-28 16:53:51.469: INFO/DEBUG(13089): 80d5f524 e07bd100 781b9b06 d1002b00 9b06e078 
11-28 16:53:51.469: INFO/DEBUG(13089): 80d5f534 f01a1c18 1c03fef1 9b1e931e d1002b00 
11-28 16:53:51.469: INFO/DEBUG(13089): code around lr:
11-28 16:53:51.469: INFO/DEBUG(13089): 80d5f960 1c18447b ed52f16d ab091c04 f16d1c18 
11-28 16:53:51.469: INFO/DEBUG(13089): 80d5f970 1c02ed4e 9b009903 1c211c08 fdb8f7ff 
11-28 16:53:51.469: INFO/DEBUG(13089): 80d5f980 930a1c03 447b4b75 21651c18 ff9cf7fe 
11-28
getFileData(...)类中的

CCFileUtils方法可以很好地获取图像但不能与其他文件一起使用。非常感谢帮助。

1 个答案:

答案 0 :(得分:1)

试试这个:

unsigned long bufferSize = 0;
unsigned char * charbuffer = CCFileUtils::sharedFileUtils()->getFileData(genrefile, "rb", &bufferSize );