Solved

jni with jstring

Posted on 2003-11-13
9
2,866 Views
Last Modified: 2013-11-23
If I want to retrieve the int from the java class via jni

I can use

jint execMode = env->GetStaticIntField(cls, env->GetStaticFieldID(cls, "APPLICATION", "I"));

where

public static final int APPLICATION=2


Question is how do I retrieve string from java class ie

public static final String CAP_INJECTION="INJ"


jstring execMode = ???
0
Comment
Question by:EDDYKT
  • 5
  • 4
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9742459
env->GetObjectField(o, env->GetFieldID(cls, "CAP_INJECTION", "Ljava/lang/String;"));
0
 
LVL 26

Author Comment

by:EDDYKT
ID: 9742499
IT throw expection



jstring execMode = (jstring)env->GetStaticObjectField(cls, env->GetStaticFieldID(cls, "CAP_INJECTION", "Ljava/lang/String;")));


I 've tried this but execMode contains jobject instead of jstring

How do I convert from jobject to jstring?

What is different between the function with/without static?
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 9742576
you just need to cast it to a jstring.

> What is different between the function with/without static?

One gets static fields, the other member fields.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 26

Author Comment

by:EDDYKT
ID: 9743838
I did but when I see the local variable (execMode) from c++ IDE, I onlt see jobject instead of jstring

Do I need to call function to cast from jobject to jstring?
0
 
LVL 92

Expert Comment

by:objects
ID: 9743892
no, just a regular cast should be fine, exactly what error are getting?


0
 
LVL 26

Author Comment

by:EDDYKT
ID: 9747341
If I use static function

ie

jstring execMode = (jstring)env->GetStaticObjectField(cls, env->GetStaticFieldID(cls, "CAP_INJECTION", "Ljava/lang/String;")));


I've no error but as what I stated

execMode contains jobject instead of jstring
when I see from c++ IDE

how can I extract the string out from jobject?
0
 
LVL 26

Author Comment

by:EDDYKT
ID: 9747593
I've asked this type of question already. It just long time ago and I've forgetten


jstring execMode = (jstring)env->GetStaticObjectField(cls, env->GetStaticFieldID(cls, "CAP_INJECTION", "Ljava/lang/String;")));

const char *name = env->GetStringUTFChars(execMode, 0);
env->ReleaseStringUTFChars((jstring) execMode, name);





0
 
LVL 92

Expert Comment

by:objects
ID: 9751340
0
 
LVL 92

Expert Comment

by:objects
ID: 9751341
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet example 17 32
Facing this issue for maven proxy setting 2 12
pagenation logic how it is working in my code 1 31
How to determine if a string is a valid SHA value 7 34
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question