ClassNotFoundException if classes are in different packages

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

ClassNotFoundException if classes are in different packages

Postby ashouric » Sun Oct 08, 2006 10:06 pm

To reproduce:

    1- Create ImageViewer:
    Code: Select all
    public class ImageViewer implements EntryPoint {

       public void onModuleLoad() {
          RootPanel rootPanel = RootPanel.get();
          rootPanel.add( new LoginWidget() );
       }

    }

    2- Create LoginWidget inside "client.widget" package, and put anything inside it.
    3- Create MyService in "client" package
    4- Make a reference to MyService inside LoginWidget:
    Code: Select all
       private MyServiceAsync service = MyService.Util.getInstance();

    5- Open ImageViewer in designer, you will have ClassNotFoundException: com.mycompany.project.client.MyService
ashouric
 
Posts: 75
Joined: Sat Sep 30, 2006 9:13 pm

Re: ClassNotFoundException if classes are in different packa

Postby Eric Clayberg » Wed Oct 11, 2006 1:45 pm

The problem is caused by the reference to the RemoteService which can't be instantiated at design time.

GWT.create(MyService.class) needs to create an instance of the class that should invoke the RemoteService implementation on the application server. During design time the application server isn't running so this doesn't work.

In the Swing world, we would get around this by wrapping the instantiation of the RemoteService with a call to Beans.isDesignTime() (which is set to true at design time and false at runtime). GWT does not support Beans.isDesignTime() (yet), so we have come up with our own alternative.

We've added support for a "private static final boolean isDesignTime() {return false;}" method. We will then replace it with "return true;" during class loading at design time (it will compile normally and be ignored at runtime). Give this a try:

Code: Select all
public class LoginComposite extends Composite {
   private final MyServiceAsync service;
   public LoginComposite() {
      if (!isDesignTime()) {
         service = MyService.Util.getInstance();
      } else {
         service = null;
      }
      {
         final FlexTable flexTable = new FlexTable();
         initWidget(flexTable);
         {
            final Button button = new Button();
            flexTable.setWidget(0, 0, button);
            button.setText("New Button");
         }
      }
   }
   private static final boolean isDesignTime() {
      return false;
   }
}
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: ClassNotFoundException if classes are in different packa

Postby ashouric » Wed Oct 11, 2006 2:50 pm

Eric Clayberg wrote:The problem is caused by the reference to the RemoteService which can't be instantiated at design time.


Fine, but one thing is against this: on directly opening "LoginWidget" which contains the reference, no error occurs. It only happens on opening "ImageViewer" that includes "LoginWidget" which contains the service.

However, as you said, it seems that the service assignment is the issue (also setting it to null resolves it).
ashouric
 
Posts: 75
Joined: Sat Sep 30, 2006 9:13 pm

Re: ClassNotFoundException if classes are in different packa

Postby Eric Clayberg » Wed Oct 11, 2006 5:54 pm

ashouric wrote:Fine, but one thing is against this: on directly opening "LoginWidget" which contains the reference, no error occurs.

Editing a class directly does not cause hat class to be instantiated, so there is no problem. Custom UI components used by a class you are editing are instantiated.

ashouric wrote: It only happens on opening "ImageViewer" that includes "LoginWidget" which contains the service.

Exactly. LoginWidget is a custom component used in ImageViewer. It is instantiated just as a Button widget would be.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 3 guests