Solved

jni with jstring

Posted on 2003-11-13
9
2,871 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 240
servlet example 11 59
ejb entity bean example issue 2 27
Eclipse with various Java releases 7 50
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

733 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