Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #25233

Re: JNI and GetFieldID

From Steven Simpson <ss@domain.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: JNI and GetFieldID
Date 2013-09-06 16:36 +0300
Organization A noiseless patient Spider
Message-ID <gb2pfa-s33.ln1@s.simpson148.btinternet.com> (permalink)
References <l0a6jn$9t4$1@node1.news.atman.pl>

Show all headers | View raw


On 05/09/13 18:05, Borneq wrote:
> I have class:

[Some spacing added.]

package net.sf.junace;

public class ACEList {
     ACEFiles files; // specifies files to be listed;

     byte[] reserved; // 64 bytes has to be filled with zeroes
}


> I call native :
> ACEList aaa = new ACEList();
> unACE.nativeACEList("abc", aaa);

> in c++ is:
> JNIEXPORT void JNICALL Java_net_sf_junace_UnACE_nativeACEList
> (JNIEnv *env, jobject jObj1, jstring archiveName, jobject jObj2)

'jObj1' corresponds to 'this', i.e. 'unACE'.  'archiveName' will be 
"abc".  'jObj2' corresponds to 'aaa'.


> which field I must read?
> jclass cls1 = env->GetObjectClass(jObj1);
> or
> jclass cls2 = env->GetObjectClass(jObj2);
> ?


> jfieldID fid = env->GetFieldID(cls1 or cls2, "something", 
> "Lnet/sf/junace/ACEList;");

> what I must choose cls1 or cls2

Since you don't say much about what type 'unACE' is, I assume you want 
to access a field of 'aaa', whose type is ACEList.  You could probably 
get it from cls2, but that is the class of the object, which could be 
ACEList or a subtype.  I think you want to get the jclass for ACEList 
directly, so perhaps:

   jclass cls = env->FindClass("net/sf/junace/ACEList");




> what I must pass as second argument as "something"?

<http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#wp16536>

It says that the string is the name of the field, so either "files" or 
"reserved".

But I think your last argument is wrong.  It should be the type 
signature of the field.  If you want the field 'files', and assuming 
that ACEFiles is in the same package as ACEList, you want 
"Lnet/sf/junace/ACEFiles;".  If you want the field 'reserved', the type 
signature is "[B".



-- 
ss at comp dot lancs dot ac dot uk

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-05 17:05 +0200
  Re: JNI and GetFieldID Mark <i@dontgetlotsofspamanymore.invalid> - 2013-09-06 10:25 +0100
  Re: JNI and GetFieldID Steven Simpson <ss@domain.invalid> - 2013-09-06 16:36 +0300
    Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-06 18:53 +0200
      Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-06 20:44 +0200
        Re: JNI and GetFieldID Steven Simpson <ss@domain.invalid> - 2013-09-06 22:34 +0300
          Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-06 23:06 +0200
      Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-07 22:27 +0200
        Re: JNI and GetFieldID Steven Simpson <ss@domain.invalid> - 2013-09-08 10:24 +0100
          Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-08 12:29 +0200
            Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-08 22:45 +0200
            Re: JNI and GetFieldID Steven Simpson <ss@domain.invalid> - 2013-09-13 13:31 +0100
              Re: JNI and GetFieldID "Borneq" <borneq@antyspam.hidden.pl> - 2013-09-14 18:50 +0200
              Re: JNI and GetFieldID "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2013-09-19 15:02 +0100

csiph-web