初学C调用java代码,出错如下:
07-14 10:36:15.028 27654-27654/study.jnidemo W/dalvikvm: JNI WARNING: CallObjectMethod expected return type 'L'
07-14 10:36:15.028 27654-27654/study.jnidemo W/dalvikvm: calling Lstudy/jnidemo/JniDemoActivity;.importCert ()V
07-14 10:36:15.028 27654-27654/study.jnidemo W/dalvikvm: in Lstudy/jnidemo/JniDemoActivity;.jniImportCert:()V (CallObjectMethod)
仔细检查C代码发现问题:
void
Java_study_jnidemo_JniDemoActivity_jniImport
(
JNIEnv
*
env
,
jobject
thiz
){
jclass
cls
=(*
env
)->
GetObjectClass
(
env
,
thiz
);
if
(
cls
!=
NULL
){
jstring
str
;
jmethodID
method3
=(*
env
)->
GetMethodID
(
env
,
cls
,
"import"
,
"()V"
);
if
(
method3
!=
NULL
){
(*
env
)->
CallObjectMethod
(
env
,
thiz
,
method3
);
}
}
}
把
(*
env
)->
CallObjectMethod
(
env
,
thiz
,
method3
);
改成
(*
env
)->
CallVoidMethod
(
env
,
thiz
,
method3
);