Search code examples
javaarchitectureobserver-patternsoftware-design

Java Observer Pattern not notifying


For some reason my observers are not being notified when i call the notifyObserver methods, using the java.util.Observable objects:

here is my observable object:

public class ProjectManager extends Observable
{
...
 public void updateProjects(String project, String pack, String source, String ARN)
{
   ...
if(newSource)
    {
    tempPack.add(tempSource);
    System.out.println("Notify observers: " + this.countObservers());
    this.notifyObservers();
    }
      ...
      }

i can see from my output that the observer is being added but not being notified.

and my observer object looks like this:

public class IDE implements Observer
{

@Override
public void update(Observable o, Object arg) {

    System.out.println("Notified");

}

For some strange reason the observable object is not being notified at all. Am i doing something wrong here?


Solution

  • You need to setChanged before you notifyObservers