Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: JNI and GetFieldID Date: Fri, 06 Sep 2013 16:36:16 +0300 Organization: A noiseless patient Spider Lines: 67 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx05.eternal-september.org; posting-host="567aef81bfffdf4c0a37048ecfe0090c"; logging-data="22245"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19svGNYWWJVmyVHW7ezBY/u8n4JqxcIshw=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8 In-Reply-To: Cancel-Lock: sha1:K753UrtiPvpVLK3uEuZXhoVerVE= Xref: csiph.com comp.lang.java.programmer:25233 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"? 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