This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes an Array of Vectors Not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "an Array of Vectors Not working" Watch "an Array of Vectors Not working" New topic

an Array of Vectors Not working

John Lister

Joined: Oct 05, 2003
Posts: 3
My code is

Teller tellersToday[] = new Teller[numberOfTellers];

// Completly ineffeciant but it works.
Vector line[] = new Vector[numberOfTellers];

I get after executing:
Exception in thread "main" java.lang.NullPointerException

Can I not do this? Or what am I doing wrong?
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Originally posted by John Lister:
Teller tellersToday[] = new Teller[numberOfTellers];

This line is only instantiating an array *of references to Vector objects*. The references are initialized with null values. If you want them to point to actual Vector objects, you need to assign those to them.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
John Lister replied with this (moved from accidental new post):
Here is what Teller is:

So If I put something into the object like currentCusomer then it would work?

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: an Array of Vectors Not working
Similar Threads
JAVA JButton Functionality
Vector of vector...
Thinking in Java's Concurrency chapter: the BankTellerSimulation example
Help!What is wrong with this program? (a simple bank account program)