urmi123
asked on
ObjectArray in JNI
Hi,
I am having two classes in java. I am trying to call one class in other class like we write structures in C.
say in a.java i have declared variables as string x; string y;
and in b.java i have variables as char lineIsSelected, String termNum, String heading1, String heading2
But i have to make b.java as array.
so i called b.java in a.java as
b []temp;
I have a numberofmatrixlines on which the loop is formed.
i had wriiten the code as follows
public void createUpdStruct(int size)
{
updStruct = new updCHSMatrixStruct[size];
}
public void setUpdStruct(int size, int index)
{
updStruct[index].lineIsSel ected = lineIsSelected;
updStruct[index].heading1 = heading1;
updStruct[index].heading2 = heading2;
updStruct[index].termNum = termNum;
}
public updCHSMatrixStruct getUpdStruct(int size)
{
return updStruct[index];
}
but when i call it on c side it fails .
can anyone help me with this.
Regds
urmilla
I am having two classes in java. I am trying to call one class in other class like we write structures in C.
say in a.java i have declared variables as string x; string y;
and in b.java i have variables as char lineIsSelected, String termNum, String heading1, String heading2
But i have to make b.java as array.
so i called b.java in a.java as
b []temp;
I have a numberofmatrixlines on which the loop is formed.
i had wriiten the code as follows
public void createUpdStruct(int size)
{
updStruct = new updCHSMatrixStruct[size];
}
public void setUpdStruct(int size, int index)
{
updStruct[index].lineIsSel
updStruct[index].heading1 = heading1;
updStruct[index].heading2 = heading2;
updStruct[index].termNum = termNum;
}
public updCHSMatrixStruct getUpdStruct(int size)
{
return updStruct[index];
}
but when i call it on c side it fails .
can anyone help me with this.
Regds
urmilla
As nesmeis propsed: Post more code, esp your C code calling the Java method.
BTW:
public updCHSMatrixStruct getUpdStruct(int size)
{
return updStruct[index];
}
should be:
public updCHSMatrixStruct getUpdStruct(int index)
{
return updStruct[index];
}
Right?
BTW:
public updCHSMatrixStruct getUpdStruct(int size)
{
return updStruct[index];
}
should be:
public updCHSMatrixStruct getUpdStruct(int index)
{
return updStruct[index];
}
Right?
GetObjectArrayElement returns the object element at a given index.
SetObjectArrayElement updates the object element at a given index.
this could be of some help to you
http://java.sun.com/docs/books/tutorial/native1.1/implementing/cpp.html
SetObjectArrayElement updates the object element at a given index.
this could be of some help to you
http://java.sun.com/docs/books/tutorial/native1.1/implementing/cpp.html
ASKER
Hi,
public void createUpdStruct(int size)
{
updStruct = new updCHSMatrixStruct[size];
}
public void setUpdStruct(int index, char lineIsSelected, String termNum, String heading1, String heading2)
{
updStruct[index].lineIsSel ected = lineIsSelected;
updStruct[index].heading1 = heading1;
updStruct[index].heading2 = heading2;
updStruct[index].termNum = termNum;
}
public updCHSMatrixStruct getUpdStruct(int index)
{
return updStruct[index];
}
This is the code i had wriiten in java.
And in c i had called it as follows
mid = (*env)->GetMethodID(env, cls, "createUpdStruct", "(I)V");
{
if (mid != NULL)
{
(*env)->CallVoidMethod(env , *jTGStruct, mid, (jint)TGStruct->numberOfMa trixLines) ;
}
}
mid = (*env)->GetMethodID(env, cls, "setUpdStruct", "(ICLjava/lang/String;Ljav a/lang/Str ing;Ljava/ lang/Strin g;)V");
{
if (mid != NULL)
{
for(index = 0; index < TGStruct->numberOfMatrixLi nes; index++)
{
jheading1 = getStringNative(env, TGStruct->updStruct[index] .heading1, strlen(TGStruct->updStruct [index].he ading1));
jheading2 = getStringNative(env, TGStruct->updStruct[index] .heading2, strlen(TGStruct->updStruct [index].he ading2));
jtermNum = getStringNative(env, TGStruct->updStruct[index] .termNum, strlen(TGStruct->updStruct [index].te rmNum));
(*env)->CallVoidMethod(env , *jTGStruct, mid, (jint)index,(jchar)TGStruc t->updStru ct[index]. lineIsSele cted, jheading1, jheading2, jtermNum);
(*env)->DeleteLocalRef(env , jheading1);
(*env)->DeleteLocalRef(env , jheading2);
(*env)->DeleteLocalRef(env , jtermNum);
}
}
}
public void createUpdStruct(int size)
{
updStruct = new updCHSMatrixStruct[size];
}
public void setUpdStruct(int index, char lineIsSelected, String termNum, String heading1, String heading2)
{
updStruct[index].lineIsSel
updStruct[index].heading1 = heading1;
updStruct[index].heading2 = heading2;
updStruct[index].termNum = termNum;
}
public updCHSMatrixStruct getUpdStruct(int index)
{
return updStruct[index];
}
This is the code i had wriiten in java.
And in c i had called it as follows
mid = (*env)->GetMethodID(env, cls, "createUpdStruct", "(I)V");
{
if (mid != NULL)
{
(*env)->CallVoidMethod(env
}
}
mid = (*env)->GetMethodID(env, cls, "setUpdStruct", "(ICLjava/lang/String;Ljav
{
if (mid != NULL)
{
for(index = 0; index < TGStruct->numberOfMatrixLi
{
jheading1 = getStringNative(env, TGStruct->updStruct[index]
jheading2 = getStringNative(env, TGStruct->updStruct[index]
jtermNum = getStringNative(env, TGStruct->updStruct[index]
(*env)->CallVoidMethod(env
(*env)->DeleteLocalRef(env
(*env)->DeleteLocalRef(env
(*env)->DeleteLocalRef(env
}
}
}
ASKER
Hi,
Following is the java code
public void createUpdStruct(int size)
{
updStruct = new updCHSMatrixStruct[size];
}
public void setUpdStruct(int index, char lineIsSelected, String termNum, String heading1, String heading2)
{
updStruct[index].lineIsSel ected = lineIsSelected;
updStruct[index].heading1 = heading1;
updStruct[index].heading2 = heading2;
updStruct[index].termNum = termNum;
}
public updCHSMatrixStruct getUpdStruct(int index)
{
return updStruct[index];
}
AN c code is as follows
mid = (*env)->GetMethodID(env, cls, "createUpdStruct", "(I)V");
{
if (mid != NULL)
{
(*env)->CallVoidMethod(env , *jTGStruct, mid, (jint)TGStruct->numberOfMa trixLines) ;
}
}
mid = (*env)->GetMethodID(env, cls, "setUpdStruct", "(ICLjava/lang/String;Ljav a/lang/Str ing;Ljava/ lang/Strin g;)V");
{
if (mid != NULL)
{
for(index = 0; index < TGStruct->numberOfMatrixLi nes; index++)
{
jheading1 = getStringNative(env, TGStruct->updStruct[index] .heading1, strlen(TGStruct->updStruct [index].he ading1));
jheading2 = getStringNative(env, TGStruct->updStruct[index] .heading2, strlen(TGStruct->updStruct [index].he ading2));
jtermNum = getStringNative(env, TGStruct->updStruct[index] .termNum, strlen(TGStruct->updStruct [index].te rmNum));
(*env)->CallVoidMethod(env , *jTGStruct, mid, (jint)index,(jchar)TGStruc t->updStru ct[index]. lineIsSele cted, jheading1, jheading2, jtermNum);
(*env)->DeleteLocalRef(env , jheading1);
(*env)->DeleteLocalRef(env , jheading2);
(*env)->DeleteLocalRef(env , jtermNum);
}
}
}
when index is set to 1 it fails .
Regds
urmilla
Following is the java code
public void createUpdStruct(int size)
{
updStruct = new updCHSMatrixStruct[size];
}
public void setUpdStruct(int index, char lineIsSelected, String termNum, String heading1, String heading2)
{
updStruct[index].lineIsSel
updStruct[index].heading1 = heading1;
updStruct[index].heading2 = heading2;
updStruct[index].termNum = termNum;
}
public updCHSMatrixStruct getUpdStruct(int index)
{
return updStruct[index];
}
AN c code is as follows
mid = (*env)->GetMethodID(env, cls, "createUpdStruct", "(I)V");
{
if (mid != NULL)
{
(*env)->CallVoidMethod(env
}
}
mid = (*env)->GetMethodID(env, cls, "setUpdStruct", "(ICLjava/lang/String;Ljav
{
if (mid != NULL)
{
for(index = 0; index < TGStruct->numberOfMatrixLi
{
jheading1 = getStringNative(env, TGStruct->updStruct[index]
jheading2 = getStringNative(env, TGStruct->updStruct[index]
jtermNum = getStringNative(env, TGStruct->updStruct[index]
(*env)->CallVoidMethod(env
(*env)->DeleteLocalRef(env
(*env)->DeleteLocalRef(env
(*env)->DeleteLocalRef(env
}
}
}
when index is set to 1 it fails .
Regds
urmilla
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
8-)
I need more code and the error message