• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help needed regarding an array

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
reply
    Bookmark Topic Watch Topic
  • New Topic