Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

converting jstring to char in c

843829Dec 3 2002 — edited Dec 3 2002
I'm trying to convert a jstring to const char (a pointer), but I keep getting an exception.
is there some kind of defenition I'm missing????

here's part of the code:


jmethodID methID;
jstring jstr;
const char *str;

/* Get a reference to obj2 class */
jclass cls = (*env)->GetObjectClass (env, obj2);
if (cls == NULL){
return; /*return in case the object couldn't be found */
}
methID = (*env)->GetMethodID (env, cls, "getPgmId", "()Ljava/lang/String;");
jstr = (jstring) (*env) -> CallCharMethod(env, obj2, methID);
if (jstr == NULL){
printf (" \nthe result String is null \n");
fflush(stdout);
return;
}
str = (char)(*env)->GetStringUTFChars (env, jstr, 0);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 31 2002
Added on Dec 3 2002
1 comment
1,267 views