Get not primary type in a class with JNI

Joined
Oct 4, 2006
Messages
1
Reaction score
0
Hello,

J try to get fields in a class with JNI. It works for primary types but J have a field whih is an object (class A contains an object class B). How can get a reference to this objet an then call the methods inside it.

Classe Essai_01 contains a method passageA which is defined in a JNI function.

Thans for your answers.


Java:
Code:
public class A {

	/**
	 * @param args
	 */
	
	B param1 = new B();
	
	int param2 = 2;
}

Code:
public class B {

	int paramB = 2;

}

Code:
public class Essai_01 {

	
	public native void callFunction();
	public native void affiche(String msg);
	public native void passageA(A obj);
	public native void passageB(B obj);
	
	
	static {
	    System.loadLibrary("MyDLL");
	  }

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Essai_01 var = new Essai_01();
		A objA = new A();
		B objB = new B();
		var.callFunction();
		var.passageA(objA);
		var.passageB(objB);
		var.affiche("ma chaine");

	}

}


Code:
JNIEXPORT void JNICALL Java_essai_101_Essai_101_passageA
  (JNIEnv * env, jobject, jobject obj) 
{
	printf("Appel fonction JNI passageA\n");
	jclass cls = env->GetObjectClass(obj);
	
	jfieldID fid = env->GetFieldID(cls, "param2", "I");
	int value = env->GetIntField(obj, fid);
	printf("param2toto : %d\n", value);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top