我的杜松子酒模塊包含以下內容:NullPointerException異常而GWT建築杜松子酒
@Override
protected void configure() {
bind(HistoryWrapper.class).to(HistoryWrapperImpl.class);
...
}
問題的類型有:
public interface HistoryWrapper {
void newItem(String token);
}
public class HistoryWrapperImpl implements HistoryWrapper {
@Override
public void newItem(String token) {}
}
當我嘗試GWT編譯,我得到以下錯誤:
Compiling module com.foo.FooGame
Validating newly compiled units
Ignored 9 units with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
Scanning for additional dependencies: file: FooGameHtml.java
Computing all possible rebind results for 'com.foo.html.client.gin.BarGinjector'
Rebinding com.foo.html.client.gin.BarGinjector
Invoking generator com.google.gwt.inject.rebind.GinjectorGenerator
[ERROR] Generator 'com.google.gwt.inject.rebind.GinjectorGenerator' threw an exception while rebinding 'com.foo.html.client.gin.BarGinjector'
java.lang.NullPointerException
at com.google.gwt.inject.rebind.BindingsProcessor.createImplicitBinding(BindingsProcessor.java:498)
at com.google.gwt.inject.rebind.BindingsProcessor.access$900(BindingsProcessor.java:99)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceBindingVisitor.addImplicitBinding(BindingsProcessor.java:982)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceBindingVisitor.visit(BindingsProcessor.java:972)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceBindingVisitor.visit(BindingsProcessor.java:898)
at com.google.inject.internal.UntargettedBindingImpl.acceptTargetVisitor(UntargettedBindingImpl.java:40)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceElementVisitor.visit(BindingsProcessor.java:827)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceElementVisitor.visit(BindingsProcessor.java:820)
at com.google.inject.internal.BindingImpl.acceptVisitor(BindingImpl.java:92)
at com.google.gwt.inject.rebind.BindingsProcessor.createBindingsForModules(BindingsProcessor.java:409)
at com.google.gwt.inject.rebind.BindingsProcessor.process(BindingsProcessor.java:238)
at com.google.gwt.inject.rebind.GinjectorGeneratorImpl.generate(GinjectorGeneratorImpl.java:76)
at com.google.gwt.inject.rebind.GinjectorGenerator.generate(GinjectorGenerator.java:47)
at com.google.gwt.core.ext.GeneratorExtWrapper.generate(GeneratorExtWrapper.java:48)
at com.google.gwt.core.ext.GeneratorExtWrapper.generateIncrementally(GeneratorExtWrapper.java:60)
at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:647)
at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:78)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:268)
at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:257)
at com.google.gwt.dev.DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(DistillerRebindPermutationOracle.java:91)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:96)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.process(AbstractCompiler.java:254)
at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:173)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:288)
at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.access$400(AbstractCompiler.java:139)
at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:588)
at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:97)
at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:52)
at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:569)
at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:33)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:284)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:233)
at com.google.gwt.dev.Precompile.precompile(Precompile.java:145)
at com.google.gwt.dev.Compiler.run(Compiler.java:232)
at com.google.gwt.dev.Compiler.run(Compiler.java:198)
at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
at com.google.gwt.dev.Compiler.main(Compiler.java:177)
[ERROR] Errors in 'src/com/foo/html/client/FooGameHtml.java'
[ERROR] Line 34: Failed to resolve 'com.foo.html.client.gin.BarGinjector' via deferred binding
Scanning for additional dependencies: jar:file:/C:/path/to/eclipse-java-indigo-win32-x86_64%20(1)/eclipse/plugins/com.google.gwt.eclipse.sdkbundle_2.4.0.v201201120043-rel-r37/gwt-2.4.0/gwt-user.jar!/com/google/gwt/core/client/impl/AsyncFragmentLoader.java
[WARN] For the following type(s), generated source was never committed (did you forget to call commit()?)
[WARN] com.foo.html.client.gin.BarGinjectorImpl
我在這裏做錯了什麼?註釋掉bind(HistoryWrapper.class)
行會使問題消失,但顯然我需要該類型的綁定。
當我試圖使用@Provides
方法時,出現類似錯誤。
更新:現在我得到一個不同的NPE,但我不知道爲什麼:
java.lang.NullPointerException
at com.google.gwt.inject.rebind.util.KeyUtil.javaToGwtMethod(KeyUtil.java:222)
at com.google.gwt.inject.rebind.binding.ProviderMethodBinding.setProviderMethod(ProviderMethodBinding.java:60)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceBindingVisitor.visit(BindingsProcessor.java:926)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceBindingVisitor.visit(BindingsProcessor.java:898)
at com.google.inject.internal.ProviderInstanceBindingImpl.acceptTargetVisitor(ProviderInstanceBindingImpl.java:52)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceElementVisitor.visit(BindingsProcessor.java:827)
at com.google.gwt.inject.rebind.BindingsProcessor$GuiceElementVisitor.visit(BindingsProcessor.java:820)
at com.google.inject.internal.BindingImpl.acceptVisitor(BindingImpl.java:92)
已經有這種無用的堆棧跟蹤。你能否提供你的類(和接口)中使用的導入列表? – 2012-02-23 21:16:08
沒有進口。類和接口全部列出。 – 2012-02-23 21:30:11
編譯器告訴您如何獲得更好的信息:「使用-strict編譯或使用-logLevel設置爲TRACE或DEBUG以查看所有錯誤。」 – 2012-02-23 21:39:20