• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed regarding an array

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to populate a variable, UPDATE_VALUES, from the fvalue hardcoded values for a JUNIT test. I need all 3 sets of UPDATE_VALUES to push into a SQL statement where an AND statement is created to hold each of the UPDATE_VALUES. Hope that makes sense. Any help or direction would be appreciated.

Here is my code.

[ September 14, 2005: Message edited by: Michael Ernest ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you're getting a null pointer exception?

what i think is happening is that while you declare your array to hold three elements, you have never CREATED those elements. In other words, your array is all set and waiting to hold three Values. when you call

UPDATE_VALUES[i].setFieldValue(fvalue);

you're saying "call the method setFieldValue() on the object in position i". There IS no object there.

you need to create three Values, and set each element of the array to point to them.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred,

Thanks for the help. You were right on track. Your time and help are appreciated.

Regards.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a better way to refactor the following code since I am obviously repeating code:

Values[] UPDATE_VALUES = new Values[3];

FieldValue fvalue = new FieldValue();
UPDATE_VALUES[0] = new Values();
fvalue.setName("NEXT.ACCT");
fvalue.setValue("savoym");
UPDATE_VALUES[0].setFieldValue(fvalue);

FieldValue fvalue1 = new FieldValue();
UPDATE_VALUES[1] = new Values();
fvalue1.setName("REC.STATUS");
fvalue1.setValue("S");
UPDATE_VALUES[1].setFieldValue(fvalue1);

FieldValue fvalue2 = new FieldValue();
UPDATE_VALUES[2] = new Values();
fvalue2.setName("NEC");
fvalue2.setValue("1001");
UPDATE_VALUES[2].setFieldValue(fvalue2);

Any HELP or DIRECTION would be appreciated.

Regards.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am by no means an expert, but you could do this:

not much help. The only other thing is if there is a better constructor for FieldValue, that would take the two strings.

I don't think you need a new reference for each FieldValue. once you use it to set your Values(), you can use the same reference for your new...



of course, this assumes you don't need the three references elsewhere. even if you do, you may be able to get them from your array, with something like

UPDATE_VALUES[2].getFieldValue();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic