需要把JAVA中的String 数组传递到本地代码中,采用如下方法,不知道如何将jobject对象向jstring对象转换。
JAVA中的定义:
String[] info = {"INFO_00", "INFO_01", "INFO_02", "INFO_03"};
PrintArrays(info);
//本地代码:
JNIEXPORT void JNICALL Java_cn_itcast_TestArray_PrintArrays(JNIEnv *env, jclass clazz, jobjectArray array)
{
int size = (*env).GetArrayLength(array); //获得数组长度,OK
for (int i = 0; i < size; i++)
{
jobject object = ((*env).GetObjectArrayElement( array, i)); //获得jobject对象
//jstring string=?? 此处不知道该如何将jobject对象向jstring对象转换
const char * chars = (*env).GetStringUTFChars( string, 0);
printf("%s n", chars);
.....
}
}谢谢!
JAVA中的定义:
String[] info = {"INFO_00", "INFO_01", "INFO_02", "INFO_03"};
PrintArrays(info);
//本地代码:
JNIEXPORT void JNICALL Java_cn_itcast_TestArray_PrintArrays(JNIEnv *env, jclass clazz, jobjectArray array)
{
int size = (*env).GetArrayLength(array); //获得数组长度,OK
for (int i = 0; i < size; i++)
{
jobject object = ((*env).GetObjectArrayElement( array, i)); //获得jobject对象
//jstring string=?? 此处不知道该如何将jobject对象向jstring对象转换
const char * chars = (*env).GetStringUTFChars( string, 0);
printf("%s n", chars);
.....
}
}谢谢!
楼主【changleqy】截止到2008-06-22 18:19:11的历史汇总数据(不包括此帖):
发帖数:30 发帖分:630
结贴数:24 结贴分:500
结贴率:80.00 % 结分率:79.37 %
楼主加油
指针对类型要求并不严格
typeof jobject jstring
....
jstring string = ((*env).GetObjectArrayElement( array, i));
const char * chars = (*env).GetStringUTFChars( string, 0);
printf("%s n", chars);
(*env).ReleaseStringUTFChars( string, chars);
....出错提示:
d:\vc\testarray\test.cpp(11) : error C2440: 'initializing' : cannot convert from 'class _jobject *' to 'class _jstring *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.