Posted By:
New_JavaGal
Posted On:
Monday, July 25, 2011 10:22 PM
Hi, I am a newbee at Java JNI and trying to print the elements of a string array that is passed from a Java program.My program below is not printing the complete strings that my java program is sending. Can someone please tell me what is wrong? Thanks in advance! New Java Gal -------------------------------------------------------------------------------- //Java program public class test9 { private native void main(int a, String[] b); public static void main(String[] args){ int x =3; String[] y = new String[3]; y[0] = "
More>>
Hi,
I am a newbee at Java JNI and trying to print the elements of a string array that is passed from a
Java program.My program below is not printing the complete strings that my java program is sending.
Can someone please tell me what is wrong?
Thanks in advance!
New Java Gal
--------------------------------------------------------------------------------
//Java program
public class test9
{
private native void main(int a, String[] b);
public static void main(String[] args){
int x =3;
String[] y = new String[3];
y[0] = "PAYMENT";
y[1] = "DATA";
y[2] = "TAPE";
System.loadLibrary("test9");
test9 t = new test9();
t.main(x,y);
}
}
-------------------------------------------------------------------------------
/* C program */
#include
#include
#include
#include "test9.h"
#include
void main(int a, char b[]);
void initial_setup(int a , char y[]);
JNIEXPORT void JNICALL
Java_test9_main(JNIEnv *env, jobject obj, jint a, jobjectArray b)
{
int len = (env) -> GetArrayLength(b);
jobject col;
int i;
const char *y;
for (i=0;i
{
col = (env) -> GetObjectArrayElement(b,i);
y = (env) -> GetStringUTFChars((jstring)col, false);
printf("%s
", &y[i]);
}
(env) -> ReleaseCharArrayElements(b,y,0);
return;
}
-------------------------------------------------------------------
/* Output */
$ java test9
PAYMENT
ATA
PE
<<Less