I'm currently working on a Java project and was having a problem with a stack overflow error. What happens is first the program reads in a file of about 1,500,000 words and adds it to an array. It then reads in a small file of about 600 words and adds it to an array. It checks how many words in the 600 word file occur in the other file. Each word in the big file is associated with a number. So when it finds a word in the big file it takes a copy of the word and its associated integer and adds it to an array. My problem is that I am getting a stack overflow error:
"AWT-EventQueue-0" java.lang.StackOverflowError
The thing is that when the small file is about 200 words the program runs fine. The last line the program has to execute is:
result.setPage("file:file for gui NEW.html");
(where result is an JEditorPane)
For some reason I get a stackoverflow error when the small file is 600 words but runs ok when it is 200 words. It runs the last line and produces this file but doesn't print it to the editor pane as that is when the exception kicks in.
Can anyone help to tell me why this may happen and how I could go about fixing it? Thanks.
The error in the console in full is:
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError at sun.awt.SunToolkit.getSystemEventQueueImplPP(Unknown Source) at sun.awt.SunToolkit.getSystemEventQueueImpl(Unknown Source) at java.awt.Toolkit.getEventQueue(Unknown Source) at java.awt.EventQueue.isDispatchThread(Unknown Source) at javax.swing.SwingUtilities.isEventDispatchThread(Unknown Source) at javax.swing.JComponent.revalidate(Unknown Source) at javax.swing.plaf.basic. BasicTextUI$RootView.preferenceChanged(Unknown Source) at javax.swing.text.View.preferenceChanged(Unknown Source) at javax.swing.text.BoxView.preferenceChanged(Unknown Source) at javax.swing.text.View.preferenceChanged(Unknown Source) at javax.swing.text.BoxView.preferenceChanged(Unknown Source) at javax.swing.text.View.preferenceChanged(Unknown Source) at javax.swing.text.BoxView.preferenceChanged(Unknown Source) (... repeating forever ...)
EDIT: So basically it seems that two controls in the GUI keep invoking each other's preferenceChanged()
method.
The Gui seems like the most likly cause because when I run the program without the gui and print the contents of the file to the console instead it works fine. I've no idea what is actually causing the problem. I'm not using preference changed routine. Only thigs like setSize(), setVisible() etc. would that cause it?