JNI create new inner Class Array

M

Martin Strube

Hi there

I have an public inner Java Class witch I want to create from a c++
..dll. How to do that?

When I want to create it on the Java side it looks like that:

// creating the Outer Class
Outer myOuter = new Outer();

// creating the inner Class as an Array (initialized with NULL)
Outer.Inner myCoord[] = new Outer.Inner[2];

// create new Inner Class Objects
myCoord[0] = myOuter.new Inner();
myCoord[1] = myOuter.new Inner();

// do sth.
myCoord[0].x = 5;
myCoord[0].y = 5;

----------------

Now I wanne do that on the C++ side. It looks like that:

jclass cls = env->FindClass("Outer$Inner");
jmethodID InnerConstructor = env->GetMethodID(cls, "<init>",
"(LOuter;)V");

// create an new Java Inner Object Array, the initelement is NULL
jobjectArray joaMyCoord = env->NewObjectArray(2, cls, NULL);

// create a new Java Inner Object, initial x,y = 0;
newObject = env->NewObject(cls, InnerConstructor);

// fill the InnerArray with Inner Elements
env->SetObjectArrayElement(joaMyCoord, 0, newObject);
env->SetObjectArrayElement(joaMyCoord, 1, newObject);


jfieldID varID = env->GetFieldID(cls,"myCoord","[LOuter$Inner;");
jobject var = env->GetObjectField(obj, varID);

// set the Java Object into the MyCoord Element on the Java side
env->SetObjectField(var, varID, joaMyCoord);

---------

Now when I want to debug the programm and want to view the stuktur of
the Inner Class Array I'll get a memory exception. Even though when I
force the GarbageCollector I'll get the memory exception. So i think
that i created the Java Object in the wrong way.

Anny Ideas?

thanks
dr.m.
 
G

Gordon Beaton

I have an public inner Java Class witch I want to create from a c++
.dll. How to do that?
[...]

Now I wanne do that on the C++ side. It looks like that:

jclass cls = env->FindClass("Outer$Inner");
jmethodID InnerConstructor = env->GetMethodID(cls, "<init>",
"(LOuter;)V");

// create an new Java Inner Object Array, the initelement is NULL
jobjectArray joaMyCoord = env->NewObjectArray(2, cls, NULL);
// create a new Java Inner Object, initial x,y = 0;
newObject = env->NewObject(cls, InnerConstructor);

So where is the "Outer" object needed by the constructor?

Did you check that this call succeeded, i.e. that newObject is not
NULL, and that no exception occurred?

/gordon
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top