I have 3 classes whose names are representative and i intend to make this work in an mvc pattern.
The following are the classes
public class view {
static int n;
static model Model=new model();
public static void main(String args[]){
Model.show(5);
System.out.println("The value is "+n);
}
}
public class model {
public interface Observer{
public void show(int n);
}
protected Observer observer;
public void setObserver(Observer observer) {
this.observer = observer;
}
public void show(int n)
{
System.out.println(n+1);
observer.show(5);
}
}
public class Logger implements model.Observer {
private view View;
public Logger(view View) {
this.View= View;
}
public void show(int n)
{
View.n=n;
}
}
I was expecting this to work in the following order
the view calls the model and the model in turn calls the observer and the observer sets the value of n in the view.
But it gives me a null pointer exception in the model when i am trying to call the observer.
Am i doing something wrong ??
setObserveris never being called soobserverisnull.