Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

an Array of Vectors Not working

 
John Lister
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code is

Teller tellersToday[] = new Teller[numberOfTellers];

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


line[0].add((Teller)tellersToday[1]);
I get after executing:
Exception in thread "main" java.lang.NullPointerException
at myprojects.bank.EventItem.startEventSystem(Bank.java:205)
at myprojects.bank.EventItem.<init>(Bank.java:140)
at myprojects.bank.Bank.displayStartQuestions(Bank.java:114)
at myprojects.bank.Bank.main(Bank.java:28)

Can I not do this? Or what am I doing wrong?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic