How to pass String[] from java to C++ using JNI
I am writing a java console application. while running that needs to pass some arguments from command prompt. So i need to process those all arguments in c++ code using JNI.
The following is my JavaCode:
class RetArray{
public native int readArray(String[] argsArr);
static{
System.loadLibrary("readArray");
}
public static void main (String[] args){
RetArray objRetArr = new RetArray();
String[] argu = new String[5];
int i = objRetArr.readArray(argu);
}
}
can u plz provide me the code in c++ ?
By the way I tried to write the code in c++ too as following:
#include <jni.h>
#include "RetArray.h"
#include <stdio.h>
#include <iostream.h>
JNIEXPORT jint JNICALL Java_RetArray_readArray(JNIEnv *env, jobject obj, jobjectArray myArray){
jint arrsize=env->GetArrayLength(env, myArray);
jobjectArray retArr = (jobjectArray)env->NewObjectArray(arrsize, env->FindClass("java/lang/String"), env->NewString(""));
for(jint i=0; i<arrsize;i++){
retArr=env->GetObejctArrayElement(myArray,i);
//printf("%c\n", retArr);
cout << retArr;
}
return 1;
}
but while making "so", its giving me lots of error.
if ne answer then do inform me at abhiforu2002@sify.com. As its very urgent for me. Thanx in Advance.

