aspose file tools*
The moose likes Beginning Java and the fly likes Help needed regarding an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help needed regarding an array" Watch "Help needed regarding an array" New topic
Author

Help needed regarding an array

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

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

Joined: Oct 02, 2003
Posts: 11479
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

Fred,

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

Regards.
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

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

Joined: Oct 02, 2003
Posts: 11479
    
  16

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();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help needed regarding an array