周末调试一则jni程序,有一处是向java返回对象数组,但是总是出错,报错如下:
# # An unexpected error has been detected by Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d8df0ed, pid=2260, tid=3168 # # Java VM: Java HotSpot(TM) Client VM (11.2-b01 mixed mode, sharing windows-x86) # Problematic frame: # V [jvm.dll+0xdf0ed] # # An error report file with more information is saved as: # C:\Documents and Settings\ad\workspace\test\hs_err_pid2260.log # # If you would like to submit a bug report, please visit: # #
|
仔细核对了c代码和java代码,没有发现什么问题,于是想到传入给c程序的java数组是简单申明了一下,但是并没有赋值,可能传入后是没有分配空间的,问题可能处在这里,于是修改:
Adapter[] a1 = new Adapter[20]; for(int i=0;i<a1.length;i++){ a1[i] = new Adapter(); }
|
在运行,果然没有问题了。
结论:jni不好用,资料又少,耽误了一下午时间,难怪官方都说不是万不得已不要用。
阅读(1283) | 评论(0) | 转发(0) |