• 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

problem with returning values to Jcombo box origin see code

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to build my combo box from getting values from db.db for origin values and I am using set to get unique values any suggestions of what I am doing wrong?
I am trying to return values to client to populate Combo box with origin I use set to keep values unique see code I get database exception.
public String[] getComboOriginValues(int fieldNum) throws DatabaseException {
invariant();
Set origin = null;
try {
seek(1); String [] values = null;int r;
for (r = 1; r <= recordCount; r++)
{
values = readRecord(); origin.add(values[fieldNum]);
}
}

catch (IOException e)
{
throw new DatabaseException(UNEXPECTED + e);
}

return (String[])origin.toArray();
//return (String[])origin.toArray(new String(0)); //this dont work
}
Thanks Lisa
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the exception at this point in my forloop
public String[] getComboOriginValues(int fieldNum) throws DatabaseException {
invariant();
Set origin = null;
try {
seek(1); String [] values = null; int r;
for (r = 1; r <= recordCount; r++)
{
values = readRecord();
//My program throws exception right before origin.add
origin.add(values[fieldNum]);
}
}
catch (IOException e)
{
throw new DatabaseException(UNEXPECTED + e);
}
return (String[])origin.toArray();
//return (String[])origin.toArray(new String(0)); //this dont work
}
thanks Lisa
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't add to a set until it has a location - you have to do new Set() first. I used a TreeSet to sort them in order.
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe Paul I tryed to new a set and said cant new an interface???
Im not sure thanks Paul
 
Lisa Foster
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul TreeSort is magic thanks Alot
Lisa
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lisa
Inadvertently I had said return (String[])values.toArray(new String(0)) which is wrong. Actually what I had meant to write was (String[])values.toArray(new String[0]) i.e. [] not (). Just correct that.
Also, getComboOriginValues() is not a happy name for a data method(). Give it a generic name.

[This message has been edited by Rahul Rathore (edited March 11, 2001).]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone have the problem like this?
using
String [] airPortCode1 = data.getDistinctValues(2);
origin = new JComboBox(airPortCode1);
String [] airPortCode2 = data.getDistinctValues(3);
destination = new JComboBox(airPortCode2);
then nothing is populated in the destination ComboBox
only either origin or destination is populated not the both.
any comment or suggestion would be appreciated!
Thanks,
Nito
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know - I filled mine with vectors and they worked fine. Where are the combo boxes declared? Initialized to null or are they new'ed at that point? Have you tried to work with the model?
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nito,
Simply enough, have you debugged what is inside airportCode1 and airportCode2?
Rudy
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nito,
When you are passing the 2 and 3, are those indices of the array that is returned from readRecord? Shouldn't they be 1 and 2 since they are zero based? Forgive me if I'm wrong, just trying to throw out suggestions...
 
Nito Raj
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out guys. Guess what, I need to move the filepointer back to the original place.
Thank you Paul and Rudy
Nito
 
reply
    Bookmark Topic Watch Topic
  • New Topic