GetStringUTFChars()函数导致的程序Crash

        今天用同事开发的JNI .so,发现一个奇怪现象,在Android2.3系统上没有问题,Android4.0以上系统就会跑出下面的异常信息:

W/dalvikvm( 3191): JNI WARNING: received null jstring
W/dalvikvm( 3191):              in Lcom/avd/dev;.OpenCamera:(Ljava/lang/String;ILjava/lang/String;ILjava/lang/String;ILjava/lang/
                                                             String;ILjava/lang/String;Ljava/lang/String;I)J (GetStringUTFChars)
I/dalvikvm( 3191): "main" prio=5 tid=1 NATIVE
I/dalvikvm( 3191):   | group="main" sCount=0 dsCount=0 obj=0x40d7a460 self=0x106abe0
I/dalvikvm( 3191):   | sysTid=3191 nice=0 sched=0/0 cgrp=default handle=1075057912
I/dalvikvm( 3191):   | schedstat=( 0 0 0 ) utm=205 stm=63 core=0
I/dalvikvm( 3191):   at com.avd.dev.OpenCamera(Native Method)
I/dalvikvm( 3191):   at com.raycommtech.ipcam.imp.p2p.SocketClient.opencamera(SocketClient.java:117)
I/dalvikvm( 3191):   at com.raycommtech.ipcam.imp.p2p.MediaFetchRayCommP2P.opencamera(MediaFetchRayCommP2P.java:623)
I/dalvikvm( 3191):   at com.raycommtech.rayfastcfg.service.RayFastcfgService.openCamera(RayFastcfgService.java:106)
I/dalvikvm( 3191):   at com.raycommtech.rayfastcfg.wlan.WifiConfigActivity$WorkHandler.handleMessage(WifiConfigActivity.java:170)
I/dalvikvm( 3191):   at android.os.Handler.dispatchMessage(Handler.java:99)
I/dalvikvm( 3191):   at android.os.Looper.loop(Looper.java:137)
I/dalvikvm( 3191):   at android.app.ActivityThread.main(ActivityThread.java:4444)
I/dalvikvm( 3191):   at java.lang.reflect.Method.invokeNative(Native Method)
I/dalvikvm( 3191):   at java.lang.reflect.Method.invoke(Method.java:511)
I/dalvikvm( 3191):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
I/dalvikvm( 3191):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
I/dalvikvm( 3191):   at dalvik.system.NativeStart.main(Native Method)
I/dalvikvm( 3191): 
E/dalvikvm( 3191): VM aborting
看提示,明显是jstring类型的参数是null导致的,网上看了下,果然有人遇到类似的问题。


        解决办法:调用GetStringUTFChars( )函数时,先判断下传入的jstring类型的变量是不是null,是就不用调用该函数,不是就可以放心的使用。

参考博客:

http://blog.csdn.net/hpccn/article/details/8112377


你可能感兴趣的:(GetStringUTFChars()函数导致的程序Crash)