Reputation: 4917
I have a simple entrypoint
class that just loads a Panel
public class TestUI implements EntryPoint
{
PanelA panelA = new PanelA();
public void onModuleLoad()
{
final RootPanel rootPanel = RootPanel.get();
rootPanel.add( panelA );
}
}
Here is PanelB
public class PanelB extends HTMLPanel
{
public PanelB()
{
super("Panel B");
final PanelA panelA = new PanelA();
Button btnNewButton = new Button("Go to panel A");
btnNewButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final RootPanel rootPanel = RootPanel.get();
rootPanel.clear();
rootPanel.add( panelA );
}
});
add(btnNewButton);
}
}
and here is panel A
public class PanelA extends HTMLPanel
{
public PanelA( )
{
super("Panel A");
final PanelB panelB = new PanelB();
Button btnNewButton = new Button("Go to panel B");
btnNewButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final RootPanel rootPanel = RootPanel.get();
rootPanel.clear();
rootPanel.add( panelB );
}
});
add(btnNewButton);
}
}
However when I try to load the page containing this entry point it fails with the exception trace below. If I replace the reference to Panel A in the entrypoint with a plain HTML panel then it loads fine. What is wrong with my simple panels? I'm basically trying to create a GUI where I can click back and forth between pages and I figured this would be the first step towards that goal.
Exception in thread "Code server for stockwatcher from Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 com.google.gwt.dev.shell.BrowserChannel$RemoteDeathError: Remote connection lost
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:536)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
at java.io.DataOutputStream.flush(Unknown Source)
at com.google.gwt.dev.shell.BrowserChannel$ReturnMessage.send(BrowserChannel.java:1310)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:533)
... 2 more
Upvotes: 0
Views: 616
Reputation: 3380
You are causing a mutual recursion or cyclic dependency call... Here is the detailed analysis...
In the TestUI
you are creating an instance of PanelA
. What happen when you create an instance of a class? Its constructor gets called. In this case PanelA
's constructor gets called. In there you are creating an instance of PanelB
and hence PanelB
's constructor gets called. Now again in PanelB
you are creating an instance of PanelA
and hence its constructor gets called and the process repeats infinitely. A better programming technique should avoid these kind of cyclic dependencies. Avoid this and it will solve your problem.
Upvotes: 3
Reputation: 13
With every Panel A you are creating, you create a new Panel B, which is itself creating a new Panel A, which is creating a new Panel B, which is infinitely continuing. Maybe that's the problem. I think you should call the constructor of panel B/panel A only in the onClick-Event.
Upvotes: 0