This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
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


Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

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