Jacob
Jacob

Reputation: 441

GWT: execution stops when adding a Composite widget to RootPanel

I have an abstract class extending Composite (AbstractWhiteBoard). Then I have a concrete class extending AbstractWhiteBoard. When I instantiate the concrete class and try to add it to the RootPanel, the program simply stops executing. There is no error or any output to direct me to a log file. I have no idea what is going wrong.

Here is my abstract class:

public abstract class AbstractWhiteBoard extends Composite {
     /*
      * FIELDS
      */
     protected HorizontalPanel WhiteBoardWrapperPanel;

     public AbstractWhiteBoard( ) {
          WhiteBoardWrapperPanel = new HorizontalPanel();
          WhiteBoardWrapperPanel.setStyleName("WhiteBoard-Wrapper");
          initWidget(WhiteBoardWrapperPanel);
     }

     /*
      * ABSTRACT PUBLIC METHODS
      */
     abstract public void addNotecard( Notecard nc );
     abstract public void addPostit( Postit postit );

     /*
      * ABSTRACT PROTECTED HELPER METHODS
      */
     abstract protected void registerDragDropControllers();
 }

And here is my concrete implementation class:

public class ConcreteWhiteBoard extends AbstractWhiteBoard {

/*
 * CONTSTRUCTORS
 */
public ConcreteWhiteBoard() {
    super();
}


/*
 * PUBLIC METHOD OVERRIDES
 */
@Override
public void addNotecard(Notecard nc) {
    // TODO Auto-generated method stub

}

@Override
public void addPostit(Postit postit) {
    // TODO Auto-generated method stub

}


/*
 * PRIVATE HELPER METHOD OVERRIDES
 */
@Override
protected void registerDragDropControllers() {
    // TODO Auto-generated method stub
}
}

So, what is happening, is I have this code:

AbstractWhiteBoard wb = new ConcreteWhiteBoard();
RootPanel.get().add(wb);
Window.alert("wb added!");

But after I add wb to the RootPanel, execution stops. The alert statement never even gets called. There is no error and I don't see anything in the log.

Is there something wrong with having an abstract class that extends Composite? Or is it something entirely different that I am just not seeing? any help is greatly appreciated!

Upvotes: 0

Views: 871

Answers (2)

Jacob
Jacob

Reputation: 441

So, this is one of those times that you feel like the most retarded developers of all time. What happened is that I was running several async calls all at the same time and I tried to refer to an object that was returned by one of those calls before it was actually created. Dunce cap on me, I got confused with async threads.

Major thanks to Daniel. Your input lead me straight to the problem!

Upvotes: 0

Daniel Kurka
Daniel Kurka

Reputation: 7985

take a look at the uncaught exception handler in gwt. if a runtime exception occurs it is called. Think of it as a global try catch around your code.

But if your code is inside your entrypoint on module load make sure to set the uncaught exception handler and call the next function within a timer (so that the uncaught exception handler is active.

For a quick example take a look here:

http://code.google.com/p/mgwt/source/browse/src/main/java/com/googlecode/mgwt/examples/showcase/client/ShowCaseEntryPoint.java?repo=showcase

In web mode you can turn on emulated stack (and get meaningful stacktraces). YOu need to add this to your gwt.xml file (only for debug purposes because it is quite slow):

<set-property name="compiler.emulatedStack" value="true" />

<set-configuration-property name="compiler.emulatedStack.recordLineNumbers" value="true" />
<set-configuration-property name="compiler.emulatedStack.recordFileNames" value="true" />

Upvotes: 1

Related Questions