Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JNi: use of GetStringChars

Status
Not open for further replies.

Gaelle

Programmer
Jun 20, 2001
62
FR
Hi !
I'm trying to use JNIs and I find it kinda hard !
Here's a portion of my code, I want to put a jstring (called PathFichiers) in a C char array (called path_temp) :

static char path_temp[255]={0}; /*global variable*/

const jchar* str;
str=(*env)->GetStringChars(env, PathFichiers, 0);
path_temp=str;
(*env)->ReleaseStringChars(env, PathFichiers,0);

I get an error sayingthat my left operande is not a lvalue.
Can someone explain me what's wrong with it ?

Thanks,
Gaelle.
 
Hello Gaelle,

One Possible solution will be this : You can try this code :

static char path_temp[255]={0}; /*global variable*/
const char* str; /* declare variable like this */

/* this returns the length of the string (jstring) */
int len = (*env)->GetStringLength(PathFichiers)+1;
/* allocate */
str = new char[len];

/* do strcpy */
strcpy(str,(*env)->GetStringChars(env, PathFichiers, 0));

path_temp=str;

delete str;
str = 0;

(*env)->ReleaseStringChars(env, PathFichiers,0);

RSP Sarathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top