5

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?

1 Answer 1

15

You need to setChanged before you notifyObservers

Sign up to request clarification or add additional context in comments.

2 Comments

+1. Another reason to dislike Java's Observable implementation.
bit of a major gotcha but I guess it might make sense from a transactional point of view.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.