Solved

Need Urgent Help

Posted on 2004-10-28
184 Views
Last Modified: 2010-03-31
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
Question by:urmi123
    23 Comments
     
    LVL 37

    Expert Comment

    by:zzynx
    >> but that is failing
    What kind of failure?
    0
     
    LVL 92

    Expert Comment

    by:objects
    how exactly is it failing?
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    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
     
    LVL 37

    Expert Comment

    by:zzynx
    Sure updStruct is initialized when you call your getters?
    0
     

    Author Comment

    by:urmi123
    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
     
    LVL 92

    Expert Comment

    by:objects
    does jTGStruct point to an instance of updCHSMatrixStruct
    0
     
    LVL 92

    Accepted Solution

    by:
    You're not passing the expected index arg in the CallCharMethod call.

    0
     
    LVL 37

    Assisted Solution

    by:zzynx
    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
     
    LVL 92

    Expert Comment

    by:objects
    jcharVal = (*env)->CallCharMethod (env, *jTGStruct, mid1, index);
    0
     

    Author Comment

    by:urmi123
    No passing index also is not solving my problem
    0
     

    Author Comment

    by:urmi123
    i am not calling createUpdStruct() before calling getUpdCHSMatrixStructLineIsSelected() as it is called during set method.
    By mistake i printed the line twice
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    >> as it is called during set method.
    What set method? Not the one you posted.
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    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
     
    LVL 92

    Expert Comment

    by:objects
    And you're sure jTGStruct is referencing an instance of updCHSMatrixStruct?
    Can you show its declaration
    0
     
    LVL 92

    Expert Comment

    by:objects
    and also where it is created.
    0
     

    Author Comment

    by:urmi123
    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
     
    LVL 37

    Expert Comment

    by:zzynx
    code?
    0
     
    LVL 92

    Expert Comment

    by:objects
    is it created in your C++ code, or returned from Java code?
    0
     

    Author Comment

    by:urmi123
    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
     
    LVL 92

    Expert Comment

    by:objects
    so hae u got it working now?
    0
     

    Author Comment

    by:urmi123
    Yup.
    Appreciate the help provided by u all.
    Thanks a lot
    0
     
    LVL 92

    Expert Comment

    by:objects
    no worries :)
    0
     
    LVL 37

    Expert Comment

    by:zzynx
    You're welcome
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now