1

I have a problem using Gin. Here is a simple example.

@GinModules(AppModule.class)
public interface AppInjector extends Ginjector
{
  MainForm getMainPanel();
  TemplateForm getHeaderForm();
}

then here is Module

import com.google.inject.Singleton;
    public class AppModule extends AbstractGinModule
    {
    @Override
    protected void configure()
    {
      bind(MainForm.class).in(Singleton.class);
    }
    }

and the Entry point

public class MySampleApplication implements EntryPoint

private final AppInjector injector = GWT.create(AppInjector.class);

public void onModuleLoad()
{
  MainForm mf = injector.getMainPanel();
  RootPanel.get().add(mf);
}
}

And the module xml file

<module rename-to="MySampleApplication">

    <!-- Inherit the core Web Toolkit stuff.                  -->
    <inherits name='com.google.gwt.user.User'/>

    <!-- Specify the app entry point class.                   -->
    <entry-point class='com.mySampleApplication.client.MySampleApplication'/>

    <inherits name="com.google.gwt.inject.Inject"/>

    <!-- Specify the app servlets.                   -->
    <servlet path='/MySampleApplicationService' class='com.mySampleApplication.server.MySampleApplicationServiceImpl'/>

</module>

After i run this code i got an exception :

ERROR: Failed to create an instance of 'com.mySampleApplication.client.MySampleApplication' via deferred binding . java.lang.RuntimeException: Deferred binding failed for 'com.mySampleApplication.client.gin.AppInjector' (did you forget to inherit a required module?).

I tried with gin 1.0 and guice 2.0.

Please, advice.

Thanks.

brakebg
  • 414
  • 3
  • 11
  • 24
  • Your code looks OK to me. Have you checked that you have all required files in the classpath: AFAIK you need gin.jar, guice.jar, aopalliance.jar – MarcoS Jun 01 '11 at 11:56
  • There must be other errors reported to guide you, hinting exactly what's wrong. – Thomas Broyer Jun 01 '11 at 12:34

1 Answers1

1
@GinModules(AppClientModule.class)

should probably be

@GinModules(AppModule.class)

Update:

The error is in line declaring AppInjector. It should be:

interface AppInjector extends Ginjector {
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • I would wish this to be the problem but it's not. :) Thanks Peter. – brakebg Jun 01 '11 at 11:31
  • Do you have '` in your .gwt.xml file? – Peter Knego Jun 01 '11 at 11:33
  • Yes, i have edited my post including the xml module file.. Any other ideas? – brakebg Jun 01 '11 at 11:39
  • Does your `MainForm` have a no-arg constructor? – Peter Knego Jun 01 '11 at 11:51
  • There is no no-arg constructor, is it matters? by the way the exception is thrown on this line : private final AppInjector injector = GWT.create(AppInjector.class); So i don't think the problem is in the no-arg constructor, what do you think? – brakebg Jun 01 '11 at 11:54
  • If there is no constructor then Java creates a default no-arg constructor. However if you have a constructor with args, but no no-arg constructor, then java does not create one. In this case GIN will throw an error, because it does not know how to instantiate a class. – Peter Knego Jun 01 '11 at 11:59
  • Other possibility might be that you are missing a jar. For Gin to work you must have: Gin, Guice and Aopalliance jars on your path. – Peter Knego Jun 01 '11 at 12:00
  • Based on where you get the error, I lean towards a missing jar. – Peter Knego Jun 01 '11 at 12:02
  • Yes, it could be but i can't figure out which jar is missing. I downloaded gin 1.5 and put it's jars in the path of my project and also in directory lib under war. Anything else i m missing? – brakebg Jun 01 '11 at 12:20
  • GIN 1.5 has two jars: one for GWT 2.2+ and one for GWT <2.2. Which GWT version do you use? You should only use one gin jar not both. – Peter Knego Jun 01 '11 at 12:39
  • Yes i got the one for 2.2+ because my GWT is 2.3 – brakebg Jun 01 '11 at 12:48
  • I have created a small project, just to setup GIN. Do you want to send you a zip file to take a look ? – brakebg Jun 01 '11 at 12:52
  • OK, post URL to zip here. I'll take a look. – Peter Knego Jun 01 '11 at 12:56
  • Ok, thanks. Here it is http://www.4shared.com/file/hzc-qjdl/gwt-gintar.html Let me know if you figure out any solution. – brakebg Jun 01 '11 at 13:03
  • It was pretty obvious when IDEA said `Deferred binding result type 'com.mySampleApplication.client.gin.AppInjector' should not be abstract`. You forgot to post this line as it is the most important error line. – Peter Knego Jun 01 '11 at 14:07
  • Yes i see now. Thanks Peter. i wish to give you rate but i dont have reputation. – brakebg Jun 01 '11 at 14:32