The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

StackOverflowError exception???

Posted by ping203 on February 22, 2002 at 11:46 AM

Hi,

You sure your program does not throw a StackOverflowError when you call setGUI???
public void setGUI(GeneManagerGUI gui) {
this.gui = gui;
manager.setGUI(gui);
}
I comment out the manager.setGUI(gui). I modify the GeneManagerGUI to String and run the following modified code, and it works fine. Did you ever call setGUI???

public class SingletonDemo {

private String gui;

private static SingletonDemo manager;
private static boolean initialized = false;


public SingletonDemo() {
this.manager = this;
initialized = true;
}

public void setGUI(String gui) {
this.gui = gui;
// manager.setGUI(gui);
}


public static SingletonDemo getGeneManager() {
if (!initialized) {
manager = new SingletonDemo();
initialized = true;
}
return manager;
}

public String getGUI()
{
return gui;
}

static void main(String args[])
{
SingletonDemo s = new SingletonDemo();
s.setGUI("A");
System.out.println(s.getGUI());
s.setGUI("B");
SingletonDemo b = SingletonDemo.getGeneManager();
System.out.println(b.getGUI());
}

}

Ping





Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us