Link to home
Start Free TrialLog in
Avatar of urmi123
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].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;
      }
Avatar of zzynx
zzynx
Flag of Belgium image

>> but that is failing
What kind of failure?
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
Sure updStruct is initialized when you call your getters?
Avatar of urmi123
urmi123

ASKER

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
does jTGStruct point to an instance of updCHSMatrixStruct
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
jcharVal = (*env)->CallCharMethod (env, *jTGStruct, mid1, index);
Avatar of urmi123

ASKER

No passing index also is not solving my problem
Avatar of urmi123

ASKER

i am not calling createUpdStruct() before calling getUpdCHSMatrixStructLineIsSelected() as it is called during set method.
By mistake i printed the line twice
>> as it is called during set method.
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 getUpdCHSMatrixStructLineIsSelected() just to check that it is initialzed.
And you're sure jTGStruct is referencing an instance of updCHSMatrixStruct?
Can you show its declaration
and also where it is created.
Avatar of urmi123

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.
code?
is it created in your C++ code, or returned from Java code?
Avatar of urmi123

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.

so hae u got it working now?
Avatar of urmi123

ASKER

Yup.
Appreciate the help provided by u all.
Thanks a lot
no worries :)
You're welcome