• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

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;
      }
0
urmi123
Asked:
urmi123
  • 9
  • 8
  • 6
2 Solutions
 
zzynxSoftware engineerCommented:
>> but that is failing
What kind of failure?
0
 
objectsCommented:
how exactly is it failing?
0
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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
 
objectsCommented:
You're not passing the expected index arg in the CallCharMethod call.

0
 
zzynxSoftware 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 9
  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now