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].lineIsSelected = 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 getUpdCHSMatrixStructLineIsSelected(int index)
      {      
            //int size            
            //updStruct = new updCHSMatrixStruct[size];
            return updStruct[index].lineIsSelected;
      }      

      public String getUpdCHSMatrixStructHeading1(int index)
      {                  
            return updStruct[index].heading1;
      }      

      public String getUpdCHSMatrixStructHeading2(int index)
      {                  
            return updStruct[index].heading2;
      }

      public String getUpdCHSMatrixStructTermNum(int index)
      {                  
            return updStruct[index].termNum;
      }
urmi123Asked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
You're not passing the expected index arg in the CallCharMethod call.

0
 
zzynxSoftware engineerCommented:
>> but that is failing
What kind of failure?
0
 
objectsCommented:
how exactly is it failing?
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
zzynxSoftware engineerCommented:
Already useful: forsee a check for bad index parameter:

if (index<0 || index > updStruct.length-1)
  // return something to indicate that an error occurred
0
 
zzynxSoftware engineerCommented:
Sure updStruct is initialized when you call your getters?
0
 
urmi123Author Commented:
I am using JNI stuff
Here i am getting the method id's for individual get ids
mid1 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructLineIsSelected", "(I)C");
mid1 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructLineIsSelected", "(I)C");
mid2 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructHeading1", "(I)Ljava/lang/String;");      
mid3 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructHeading2", "(I)Ljava/lang/String;");      
mid4 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructTermNum", "(I)Ljava/lang/String;");      

and calling the methods like this
for(index = 0; index < TGStruct->numberOfMatrixLines; index++)
{                  
jcharVal = (*env)->CallCharMethod (env, *jTGStruct, mid1);
TGStruct->updStruct[index].lineIsSelected = (char)jcharVal;
}
jcharVal  is returned null and it is failing
0
 
objectsCommented:
does jTGStruct point to an instance of updCHSMatrixStruct
0
 
zzynxConnect With a Mentor Software engineerCommented:
Again, are you sure that createUpdStruct() is called before getUpdCHSMatrixStructLineIsSelected()?

Just a remark:
Why do you have this line twice?
>>         mid1 = (*env)->GetMethodID(env, cls, "getUpdCHSMatrixStructLineIsSelected", "(I)C");

0
 
objectsCommented:
jcharVal = (*env)->CallCharMethod (env, *jTGStruct, mid1, index);
0
 
urmi123Author Commented:
No passing index also is not solving my problem
0
 
urmi123Author Commented:
i am not calling createUpdStruct() before calling getUpdCHSMatrixStructLineIsSelected() as it is called during set method.
By mistake i printed the line twice
0
 
zzynxSoftware engineerCommented:
>> as it is called during set method.
What set method? Not the one you posted.
0
 
zzynxSoftware engineerCommented:
Maybe you could add a function:

public int getUpdStructSize() {              
          return updStruct.length;
}

and call it before calling getUpdCHSMatrixStructLineIsSelected() just to check that it is initialzed.
0
 
objectsCommented:
And you're sure jTGStruct is referencing an instance of updCHSMatrixStruct?
Can you show its declaration
0
 
objectsCommented:
and also where it is created.
0
 
urmi123Author Commented:
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.
0
 
zzynxSoftware engineerCommented:
code?
0
 
objectsCommented:
is it created in your C++ code, or returned from Java code?
0
 
urmi123Author Commented:
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.

0
 
objectsCommented:
so hae u got it working now?
0
 
urmi123Author Commented:
Yup.
Appreciate the help provided by u all.
Thanks a lot
0
 
objectsCommented:
no worries :)
0
 
zzynxSoftware engineerCommented:
You're welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.