Solved

jni with jstring

Posted on 2003-11-13
9
2,875 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

617 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