需要把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);
          .....
        }
}谢谢!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【changleqy】截止到2008-06-22 18:19:11的历史汇总数据(不包括此帖):
    发帖数:30                 发帖分:630                
    结贴数:24                 结贴分:500                
    结贴率:80.00     %        结分率:79.37     %        
    楼主加油
      

  2.   

    这个地方应该可以直接接收的,因为是用指针指向一串地址值。然后用GetStringUTFChars
    指针对类型要求并不严格
      

  3.   

    而且jni定义的jstring就是jobject
    typeof jobject jstring
      

  4.   

    本来我也这么以为的,但运行结果却有错误:
    ....
    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 时出错.
      

  5.   

    ban fanhttp://java.sun.com/developer/onlineTraining/Programming/JDCBook/jnistring.htmlMK