[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Need Urgent Help

Posted on 2004-10-28
25
Medium Priority
?
190 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
Comment
Question by:urmi123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
  • 6
25 Comments
 
LVL 37

Expert Comment

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

Expert Comment

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

Expert Comment

by:zzynx
ID: 12431000
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
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.

 
LVL 37

Expert Comment

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

Author Comment

by:urmi123
ID: 12431039
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
ID: 12431057
does jTGStruct point to an instance of updCHSMatrixStruct
0
 
LVL 92

Accepted Solution

by:
objects earned 252 total points
ID: 12431065
You're not passing the expected index arg in the CallCharMethod call.

0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 248 total points
ID: 12431066
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
ID: 12431067
jcharVal = (*env)->CallCharMethod (env, *jTGStruct, mid1, index);
0
 

Author Comment

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

Author Comment

by:urmi123
ID: 12431129
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
ID: 12431136
>> as it is called during set method.
What set method? Not the one you posted.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12431147
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
ID: 12431223
And you're sure jTGStruct is referencing an instance of updCHSMatrixStruct?
Can you show its declaration
0
 
LVL 92

Expert Comment

by:objects
ID: 12431227
and also where it is created.
0
 

Author Comment

by:urmi123
ID: 12431363
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
ID: 12431378
code?
0
 
LVL 92

Expert Comment

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

Author Comment

by:urmi123
ID: 12431511
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
ID: 12431517
so hae u got it working now?
0
 

Author Comment

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

Expert Comment

by:objects
ID: 12431593
no worries :)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12431607
You're welcome
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

649 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