Hey guys, gonna try and explain this in an hopefully understandable way.
I've got my GUI which is called a GUI class which is a singleton so I can access it anywhere in my code and manipulate the GUI object.
I've also got a sharedMemorySection which again is a singleton which stores an ArrayList<string> allowing the system to post messages into the arraylist.
The problem starts to come to light when the messageListeners are invoked since they grab an instance of the GUI class in order to post a message but in order to create a GUI instance we need a messageListener and therefore I seem to get into an inifintive loop and a runtimestack overflow occurs.
Basically
Gui -> makes listener (but GUI is still set to NULL because it ain't finished been set up)
listener -> needs object of GUI so requests a new object since its still set to NULL
Hence a infinitive loop of getInstance calls occurs.
I'm wondering if theres a way rnd this?
//my customer logger that enables me to save messages to the arrayList
//in GUI class....
variables....
...
private static Logger diagnosticLog = DiagnosticLogger.getInstance().getLogger();
..
..
public static Gui getInstance() {
diagnosticLog.log(Level.INFO, "HELLlllllllllllOOOOOOOOOOOOOOOO");
if (frame == null) {
frame = new Gui("BTServer");
frame.setSize(60,40);
createAndShowGUI();
}
return frame;
}
//Constructor of the class....
private Gui(String name) {
super(name);
Listener listenerOnMemoryArea = new Listener();
SharedMemorySection.getInstance().registerListenerOntoSharedMemory (listenerOnMemoryArea);
diagnosticLog.log(Level.INFO, "Creeating an object of GUI()");
// the Listener object...
Gui instance;
public Listener() {
instance = Gui.getInstance();
}
/**
* Puts the strings onto a canvas
*
* @param stringList - the list of messages to be displayed to the user.
*/
public void printMessagesToUser ( List<String> stringList) {
//Iterate through the list
Iterator <String> it = stringList.listIterator ();
while(it.hasNext ()) {
String str = StringFormatter.stringFormatter (it.next ());
if(str == null) {
return;
}
// instance.logThisMessage ("USER",str);
System.out.println(" ******************" + this.toString() + " " + str);
}
}
}
Hope this all make sence?