The Artima Developer Community
Sponsored Link •

Design Forum
trouble adding to a vector

2 replies on 1 page. Most recent reply: Jun 14, 2002 3:32 PM by Thomas SMETS

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
jake

Posts: 83
Nickname: onorok
Registered: May, 2002

trouble adding to a vector Posted: Jun 5, 2002 7:24 PM
Reply to this message Reply
Advertisement
Why won't this work??
-----------------------------------
import java.util.Vector;
public class Customer
{
public Vector bankCustomers;
String first_name, last_name;
long phone_number;

public Customer()
{
bankCustomers=new Vector();
}

public void newCustomer(String Fname, String Lname, long phoneN)
{
this.first_name=Fname;
this.last_name=Lname;
this.phone_number=phoneN ;

//Adds the new Customer to the BankCustomer Vector.
bankCustomers.addElement(newCustomer(Fname,Lname,phoneN));
}
}

------- -------------------------------------------
this is the error.


--------------------Configuration: JDK version 1.3 <Default>------------------------------------------------
C:\Program Files\Xinox Software\JCreator\MyProjects\Customer.java:20: 'void' type not allowed here
bankCustomers.addElement(newCustomer(Fname,Lname,phoneN));
^
1 error
Process completed.


pavan

Posts: 1
Nickname: cracker
Registered: Jun, 2002

Re: trouble adding to a vector Posted: Jun 6, 2002 2:19 PM
Reply to this message Reply
Watch your code again..
Vector 's addElement takes Object as a parameter and your method is returning a "void"..
Also the addElement method should be placed outside the method body "newCustomer"..

Hope this solved ur problem..

Cracker

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: trouble adding to a vector Posted: Jun 14, 2002 3:32 PM
Reply to this message Reply
May be should you use ArrayList instead (java.util.ArrayList).
More generic, faster....

Rgds,

Thomas SMETS,
SCJP2 - Brussels

Flat View: This topic has 2 replies on 1 page
Topic: trouble adding to a vector Previous Topic   Next Topic Topic: Design Schools and Distance Education

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use