Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jni with jstring

Posted on 2003-11-13
9
Medium Priority
?
2,908 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 600 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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: 9751341
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

927 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