i am using guice with java play framework.
i have a simple command interface, and a implementor created in java like this:
public interface ICommand {
public void test();
}
And the implementor
public class CommandImpl implements ICommand {
@Override
public void test() {
System.out.println("test");
}
And then the binding class for @Inject:
public class ICommandModule extends AbstractModule{
@Override
protected void configure() {
bind(ICommand.class).to(CommandImpl.class);
}
}
When i try the command like this:
@Inject
private static ICommand Command;
public static void index() {
Command.test();
render();
}
i get these errors:
From Web Browser:
Execution exception
NullPointerException occured : null
From the Console:
Execution exception (In /app/controllers/Application.java around line 27) NullPointerException occured : null
play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by:
java.lang.NullPointerException
at controllers.Application.index(Application.java:27)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161) ... 1 more
Thanks for helping!
You are using
static.Injectworks only on instance variable and constructors.You need to use
requestStaticInjectionin your module.