• 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

Problems with vectors

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1436
6
Python TypeScript Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you both, that cleared up the problem.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic