• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Problem while returning an object using JNI and accessing its fields and methods?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to return an java object(IPDetails) from a java method using JNI.
I am using the following code for this.But the NULL value is getting.
Why this is becoming NULL.Is this the correct way of returning an Object
from a java function?
jobject ipDetails;
ipDetails = (*env)->CallObjectMethod(env,jobj,methodID,(*env)->NewStringUTF(env,userName));
The IPDetails class has 2 fields
a String field (ip) and a boolean field (accept)
.I want the 2 field values to be retrieved from the object
returned from the java method and be used in the C program.
For that,
jclass detailsClass = (*env)->FindClass(env,"com/test/IPDetails");
jfieldId ipID = (*env)->GetFieldID(env,detailsClass,"ip","Ljava/lang/String;");
jboolean acceptID = (*env)->GetFieldID(env,detailsClass,"accept","Z");
For getting the ip and accept fields of the ipDetails object which function
shall i use??
Can anyone suggest how can i call and get the above two fields
of the object returned.
Thanks
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Manesh,
I did not get one thing, where are you instantiating the IPDetails object? Whether the instance of IPDetails is passed as a parameter in the native method.
I guess that you are trying to access the fields of the IPDetails instance,
For accessing the field of any instance you have to use

Some examples:

you have to pass the field id returned by the GetFieldId function. Also you can refer to the JNI documentation available within the Java API Documentation.
Hope this helps
[ February 21, 2003: Message edited by: Vijayakumar Arya ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic