• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with vectors

 
Sal Velinus
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with this vector/iterator code? When it was coded as an array, it was ok. Everything compiles ok till here:

Here's the error message:

Thanks.
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you remember to import java.util.*?
Did you use JDK 1.2 and above?
 
Sal Velinus
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, got it down to one error, but can't figure it out.

The error code now:

getSize() is a method defined in class MemoryChip, which is in the same package and which is referenced in several other places in this class w/o problem.
The vector here holds MemoryChip objects. My thinking is that (chip.next()) should refer to an element in the vector of type MemoryChip, and so return getSize(). Doesn't work. Thanks for the help.
[ April 03, 2002: Message edited by: Greg Adams ]
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the case is correct?
In the compiler error, I see a getsize (lowercase 's') and you are talking about getSize (uppercase 's'). May that be the reason?
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Iterator.next() method returns an "Object" type. You have to cast it back to "MemoryChip" before the compiler can check the "getsize()" method for you.
Try this:
totalRam += ((MemoryChip) chip.next()).getsize();
[ April 03, 2002: Message edited by: Michael Yuan ]
 
Sal Velinus
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both, that cleared up the problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic