Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Recovery of values of fields from his ID in JNI

Posted on 2004-08-18
16
Medium Priority
?
219 Views
Last Modified: 2013-11-23
If I have an ID of a field in JNI, how Can I know its value
(if it is a primitive) or reference (if it is an object) and modify it?

UJM
0
Comment
Question by:ujuarez71
[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
  • 6
  • 5
  • 4
16 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11836319
Can you elaborate on

>>If I have an ID of a field in JNI

?
0
 

Author Comment

by:ujuarez71
ID: 11836357
I have an ID field, so I want to know its value.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 11836386
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 92

Expert Comment

by:objects
ID: 11836447
Use the releveant GetXXXField() method depending on the type of the field.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 300 total points
ID: 11836449
heres an example:

#include <stdio.h>
#include <jni.h>
#include "FieldAccess.h"

JNIEXPORT void JNICALL
Java_FieldAccess_accessFields(JNIEnv *env, jobject obj)
{
  jclass cls = (*env)->GetObjectClass(env, obj);
  jfieldID fid;
  jstring jstr;
  const char *str;
  jint si;

  printf("In C:\n");

  fid = (*env)->GetStaticFieldID(env, cls, "si", "I");
  if (fid == 0) {
    return;
  }
  si = (*env)->GetStaticIntField(env, cls, fid);
  printf("  FieldAccess.si = %d\n", si);
  (*env)->SetStaticIntField(env, cls, fid, 200);
 
  fid = (*env)->GetFieldID(env, cls, "s", "Ljava/lang/String;");
  if (fid == 0) {
    return;
  }
  jstr = (*env)->GetObjectField(env, obj, fid);
  str = (*env)->GetStringUTFChars(env, jstr, 0);
  printf("  c.s = \"%s\"\n", str);
  (*env)->ReleaseStringUTFChars(env, jstr, str);

  jstr = (*env)->NewStringUTF(env, "123");
  (*env)->SetObjectField(env, obj, fid, jstr);
}


0
 

Author Comment

by:ujuarez71
ID: 11836675
This apply for arguments too? That Is, given a method identifier, how I can obtain the values of its arguments?
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 11836715
Arguments are passed when a method is called. A method alone does not have argument values.
0
 

Author Comment

by:ujuarez71
ID: 11836753
Then, the only thing that I can do is to define native methods in my source code and to pass the arguments that I need. That's right?
0
 
LVL 92

Expert Comment

by:objects
ID: 11836768
yes
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11836816
>>Then, the only thing that I can do ...

What is it that you're trying to do in fact?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11836841
ujuarez71, can you say

a. Why you ignored the correct comment I gave that answered your question?
b. Why you accepted an answer to a different question?
0
 

Author Comment

by:ujuarez71
ID: 11836974
I apologize widely by the incident. My doubt extended and was
clarified quickly. My error was not to raise another new question or to distribute the points.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11837043
>>or to distribute the points

It's still possible to do that by posting a 0-point question to CS ;-)

http://www.experts-exchange.com/Community_Support/
0
 
LVL 92

Expert Comment

by:objects
ID: 11837463
My additional clarifications should deserve a larger share of the split :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11846016
Thanks ;-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 …
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

636 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