aspose file tools*
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
Author

Simple vector prob

Jon omara
Greenhorn

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(Subject.java:15)
at Driver.main(Driver.java:17)
[ 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: http://aspose.com/file-tools
 
subject: Simple vector prob
 
Similar Threads
not using any loops
Queueing of call in GWT
Umm, how does Observer work?
Is this MVC
what is Observable class and Observer interface