• Post Reply Bookmark Topic Watch Topic
  • New Topic

stuck on infinite loop  RSS feed

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I'm struggling with an infinite loop issue which causes a java.lang.StackOverflowError and don't know how to fix it. I'll reference you to a sample Wizard Dialog I am trying to recreate at: http://www.java2s.com/Code/Java/Swing-Components/WizardDialogwithLogo.htm

I'll show you three classes: KeywordGenerator, DefaultJWizardComponents, and SimpleLogoJWizardFrame



Here's what's happening when I'm in DEBUG mode:
1. The KeywordGenerator class creates an instance of SimpleLogoJWizardFrame in the init() method
2. The KeywordGenerator.init() method finally calls on the SimpleLogoJWizardFrame.show() method
3. SimpleLogoJWizardFrame.show() method, as you can see, calls DefaultJWizardComponents.updateComponents() method, then the setVisible(true) method.

At this point you would expect that to be the end of it, BUT NO! After the setVisible(true) method is called, it steps back to the updateComponents() call and just keeps repeating those two calls over and over again. I've not experienced this before. I don't understand why it is doing that.

I don't know if it is of any importance or not, but I'm using Eclipse Helios as my IDE.

Please advise,

Alan
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something must be calling your show method over and over. If nothing else, put in a bunch of "System.out.println()" statements everywhere. Put one at the start and end of every method, like "entering show()" and "leaving show()"

 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the prompt reply. I did what you suggested. In the KeywordsGenerator.init() method I wrote:

System.out.println("KeywordGenerator.init(): entering show");
wizardFrame.show();
System.out.println("KeywordGenerator.init(): leaving show");

In the SimpleLogoJWizardFrame class I wrote:

public void show()
{
System.out.println("SimpleLogoJWizardFrame.show(): entering show");
wizardComponents.updateComponents();
setVisible(true);
System.out.println("SimpleLogoJWizardFrame.show(): leaving show");
}

The console prints out the following:

KeywordGenerator.init(): entering show
SimpleLogoJWizardFrame.show(): entering show
SimpleLogoJWizardFrame.show(): entering show
...

So, what's happening is that once the setVisible() method is finished, it doesn't execute the println statement that follows. Instead, it returns to the top println statement and keeps repeating.

I might point out that the original code made a deprecated call to super.show(), but I changed it to setvisible(true). I just discovered this is where the problem lies. JFrame has a deprecated method called show(). The original author of the SimpleLogoJWizardFrame extends JFrame class created this method show(). I changed the name to showFrame().

So now, in the KeywordsGenerator.init() method I wrote:

System.out.println("KeywordGenerator.init(): entering show");
wizardFrame.showFrame();
System.out.println("KeywordGenerator.init(): leaving show");

and in the SimpleLogoJWizardFrame class I changed the show() method to showFrame()

public void showFrame()
{
System.out.println("SimpleLogoJWizardFrame.show(): entering show");
wizardComponents.updateComponents();
setVisible(true);
System.out.println("SimpleLogoJWizardFrame.show(): leaving show");
}


The project is now working properly. Thanks for your assistance.

Alan
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!