wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes problem with returning values to Jcombo box origin see code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "problem with returning values to Jcombo box origin see code" Watch "problem with returning values to Jcombo box origin see code" New topic
Author

problem with returning values to Jcombo box origin see code

Lisa Foster
Ranch Hand

Joined: Feb 28, 2001
Posts: 116
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

Joined: Feb 28, 2001
Posts: 116
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
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
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

Joined: Feb 28, 2001
Posts: 116
I believe Paul I tryed to new a set and said cant new an interface???
Im not sure thanks Paul
Lisa Foster
Ranch Hand

Joined: Feb 28, 2001
Posts: 116
Thanks Paul TreeSort is magic thanks Alot
Lisa
Rahul Rathore
Ranch Hand

Joined: Sep 30, 2000
Posts: 324
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).]
Nito Raj
Greenhorn

Joined: Dec 04, 2000
Posts: 5
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

Joined: Jun 02, 2000
Posts: 244
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?
Rudy Yeung
Ranch Hand

Joined: Dec 27, 2000
Posts: 183
Nito,
Simply enough, have you debugged what is inside airportCode1 and airportCode2?
Rudy
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
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

Joined: Dec 04, 2000
Posts: 5
I figured it out guys. Guess what, I need to move the filepointer back to the original place.
Thank you Paul and Rudy
Nito
 
 
subject: problem with returning values to Jcombo box origin see code
 
Similar Threads
RMI Question?????
method criteriaFind
Trying to pull out Unique values from database
suncertify.db.Data
about criteriaFind