File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Simple vector prob Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Simple vector prob" Watch "Simple vector prob" New topic

Simple vector prob

Jon omara

Joined: Feb 14, 2004
Posts: 1
Hi i am trying to build a simple observer class but am having a problem with something that should be realtivley staright foward. In my main method below on complilation the following error is generated and i was wondering if anyone could spot a prolem with the way i have passed the string to the vector
Many thanks
C:\>java Driver
Subject Vector created...
New Observer one Created...
New Observer two Created...
New Observer three Created...
Exception in thread "main" java.lang.NullPointerException
at Subject.addSubject(
at Driver.main(
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ February 15, 2004: Message edited by: Dirk Schreckmann ]
Adrian Yan
Ranch Hand

Joined: Oct 02, 2000
Posts: 688
You never initialize the Vector hector in your class scope.

As you can see in your constructor, your initialized a new object called hector but only for your local scope. And then you try to add element to your global level Vector hector, which was never initialized. Just make your constructor like this:
I agree. Here's the link:
subject: Simple vector prob
It's not a secret anymore!