Capturing the return values of a 2d array
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Daniel_Ray
Posted On:   Thursday, October 25, 2001 08:22 AM

My java method public String[][] Get2DArray() { String retList[][]; retList = new String[3][5]; ...set elements in array.. return retList; } I create a .class file instead of a .h file. My C++ app uses a pointer to the JVM to access my other methods. I can get return values on my other java methods, but I can not capture and assign the values of retList. I understand that I will get each element one at a time and assign them as jstrings and then do the conversion. I can't seem to figure out how to get access the retList array with GetObjectArrayElement. This doesn't seem to use a method id like my other functions. Little help or   More>>

My java method



public String[][] Get2DArray()

{

String retList[][];


retList = new String[3][5];


...set elements in array..


return retList;

}



I create a .class file instead of a .h file. My C++ app uses a pointer to the JVM to access my other methods. I can get return values on my other java methods, but I can not capture and assign the values of retList. I understand that I will get each element one at a time and assign them as jstrings and then do the conversion. I can't seem to figure out how to get access the retList array with GetObjectArrayElement. This doesn't seem to use a method id like my other functions. Little help or an example would be great. Thank you

   <<Less

Re: Capturing the return values of a 2d array

Posted By:   Daniel_Ray  
Posted On:   Friday, October 26, 2001 12:48 PM

This is one solution I've found

Assumes that you've already obtained the method ID
Because method is not static, we pass an instance of the class
jobject jobj instead of the jclass cls




jobjectArray jray = (jobjectArray)penv->CallObjectMethod(jobj, MID);

jsize firstSize = penv->GetArrayLength(jray);


for(int i=0; i
{

   jobjectArray firstDimension = (jobjectArray)penv->GetObjectArrayElement(jray, i);

   jsize secondSize = penv->GetArrayLength(firstDimension);



   for(int j=0; j
   {

      jstring jstr = (jstring)penv->GetObjectArrayElement(firstDimension, j);

      const char *temp = penv->GetStringUTFChars(jstr, 0);


      // Print out value of temp (C++ Builder)

      JNITestFormRichEdit->Lines->Add(temp);


      // Free the memory
penv->ReleaseStringUTFChars(jstr, temp);

   }

}
About | Sitemap | Contact