Wrox Programmer Forums
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 22nd, 2003, 08:22 AM
Registered User
 
Join Date: Jul 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to chikodi
Default vector.add();

I tried to add an int variable to a vector:
{
int i = (int)tokenizer.nval;
Vector v = new Vector();
v.add(i);
}
Alas! The compiler error says "cannot resolve symbol", but similar String variable compiles well.

Who knows what the problem is.

Thanks.

nbc
 
Old October 22nd, 2003, 09:05 AM
Registered User
 
Join Date: Jun 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you look at the API, you'll see that the add method takes boolean add(Object o) an Object - so you cannot add primative data. You need to wrap the int in a suitable wrapper class like java.lang.Integer.

For more info on the java.lang.Integer object:
http://java.sun.com/j2se/1.4.2/docs/...g/Integer.html
 
Old October 23rd, 2003, 02:03 AM
Authorized User
 
Join Date: May 2003
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI
The error is b'cos you are trying to add a primitive type to a vector where as the add(Object o) takes an Object as argument so to add an int value to a vector u can do it this way

int i = (int)tokenizer.nval;
Vector v = new Vector();
v.add(new Integer(i));

Regards

Yashraj Chauhan
Java\J2EE Specialist
Wiley Support Team





Similar Threads
Thread Thread Starter Forum Replies Last Post
Vector problem ronnie5 C++ Programming 3 November 9th, 2005 08:18 AM
vector.add(); -- Reference or Object? Firedawn Servlets 2 February 23rd, 2005 01:04 AM
help add, delete from a JList in a Vector egolileopablo J2EE 1 January 1st, 2005 06:16 AM
Trouble Using Vector Iain C++ Programming 0 April 7th, 2004 08:12 PM
help me add, delete from a JList in a Vector egolileopablo Java GUI 0 October 22nd, 2003 09:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.