urmi123
asked on
Need Urgent Help
Hi,
I have the following code. Can anyone pls tell me what is wrong with the get methods.
public void createUpdStruct(int size)
{
int len, index;
updStruct = new updCHSMatrixStruct[size];
len = Array.getLength(updStruct) ;
for (index=0; index<len; index++)
{
updStruct[index] = new updCHSMatrixStruct();
}
}
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;
}
Next is get method for the individual parameters but that is failing and here is the code
public char getUpdCHSMatrixStructLineI sSelected( int index)
{
//int size
//updStruct = new updCHSMatrixStruct[size];
return updStruct[index].lineIsSel ected;
}
public String getUpdCHSMatrixStructHeadi ng1(int index)
{
return updStruct[index].heading1;
}
public String getUpdCHSMatrixStructHeadi ng2(int index)
{
return updStruct[index].heading2;
}
public String getUpdCHSMatrixStructTermN um(int index)
{
return updStruct[index].termNum;
}
I have the following code. Can anyone pls tell me what is wrong with the get methods.
public void createUpdStruct(int size)
{
int len, index;
updStruct = new updCHSMatrixStruct[size];
len = Array.getLength(updStruct)
for (index=0; index<len; index++)
{
updStruct[index] = new updCHSMatrixStruct();
}
}
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;
}
Next is get method for the individual parameters but that is failing and here is the code
public char getUpdCHSMatrixStructLineI
{
//int size
//updStruct = new updCHSMatrixStruct[size];
return updStruct[index].lineIsSel
}
public String getUpdCHSMatrixStructHeadi
{
return updStruct[index].heading1;
}
public String getUpdCHSMatrixStructHeadi
{
return updStruct[index].heading2;
}
public String getUpdCHSMatrixStructTermN
{
return updStruct[index].termNum;
}
how exactly is it failing?
Already useful: forsee a check for bad index parameter:
if (index<0 || index > updStruct.length-1)
// return something to indicate that an error occurred
if (index<0 || index > updStruct.length-1)
// return something to indicate that an error occurred
Sure updStruct is initialized when you call your getters?
ASKER
I am using JNI stuff
Here i am getting the method id's for individual get ids
mid1 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructLine IsSelected ", "(I)C");
mid1 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructLine IsSelected ", "(I)C");
mid2 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructHead ing1", "(I)Ljava/lang/String;");
mid3 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructHead ing2", "(I)Ljava/lang/String;");
mid4 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructTerm Num", "(I)Ljava/lang/String;");
and calling the methods like this
for(index = 0; index < TGStruct->numberOfMatrixLi nes; index++)
{
jcharVal = (*env)->CallCharMethod (env, *jTGStruct, mid1);
TGStruct->updStruct[index] .lineIsSel ected = (char)jcharVal;
}
jcharVal is returned null and it is failing
Here i am getting the method id's for individual get ids
mid1 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructLine
mid1 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructLine
mid2 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructHead
mid3 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructHead
mid4 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructTerm
and calling the methods like this
for(index = 0; index < TGStruct->numberOfMatrixLi
{
jcharVal = (*env)->CallCharMethod (env, *jTGStruct, mid1);
TGStruct->updStruct[index]
}
jcharVal is returned null and it is failing
does jTGStruct point to an instance of updCHSMatrixStruct
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
jcharVal = (*env)->CallCharMethod (env, *jTGStruct, mid1, index);
ASKER
No passing index also is not solving my problem
ASKER
i am not calling createUpdStruct() before calling getUpdCHSMatrixStructLineI sSelected( ) as it is called during set method.
By mistake i printed the line twice
By mistake i printed the line twice
>> as it is called during set method.
What set method? Not the one you posted.
What set method? Not the one you posted.
Maybe you could add a function:
public int getUpdStructSize() {
return updStruct.length;
}
and call it before calling getUpdCHSMatrixStructLineI sSelected( ) just to check that it is initialzed.
public int getUpdStructSize() {
return updStruct.length;
}
and call it before calling getUpdCHSMatrixStructLineI
And you're sure jTGStruct is referencing an instance of updCHSMatrixStruct?
Can you show its declaration
Can you show its declaration
and also where it is created.
ASKER
TgStruct is a class inside which updCHSMatrixStruct is called.
and it called inside TGStruct as updCHSMatrixStruct []updStruct;
when i allocate the memory to the main structure my embedded structutre becomes null.
so may be that is the problem.
and it called inside TGStruct as updCHSMatrixStruct []updStruct;
when i allocate the memory to the main structure my embedded structutre becomes null.
so may be that is the problem.
code?
is it created in your C++ code, or returned from Java code?
ASKER
Memory is allocated in C.
I had allocated the memory to main structure but had not allocated to embedded structure.
That was the reason it was failing.
I had allocated the memory to main structure but had not allocated to embedded structure.
That was the reason it was failing.
so hae u got it working now?
ASKER
Yup.
Appreciate the help provided by u all.
Thanks a lot
Appreciate the help provided by u all.
Thanks a lot
no worries :)
You're welcome
What kind of failure?