Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 369
Ben Flowers Avatar asked Jul 03 '12 16:07

Ben Flowers


1 Answers

You need to setChanged before you notifyObservers

like image 154
Jacob Raihle Avatar answered Sep 19 '22 16:09

Jacob Raihle