Roboguice在发布会上疯狂应用程序

时间:2014-05-06 22:08:59

标签: java android gradle guice roboguice

这很奇怪。我在所有最近使用相同库的项目中使用了Roboguice 2.0,一切都很好。我开始了全新的项目,并且在我的应用程序启动时出现了一些令人毛骨悚然的错误。我从各地开始搜索,但所有问题都与旧的或解决方案无法解决的问题相对应。

来自Jaime Lannister的金色指甲回答了这场噩梦!

我使用Android Studio和libs:

- guice-3.0-no_aop
- javax.inject-1
- jsr305-1.3.9
- roboguice-2.0
- in other modules there are Spring-for-android-REST and GreenDao libs, if it matters

课程扩展申请:

public class JudgementSearcherApp extends Application {

    @Inject private InitAppCommand initApp;

    @Override
    public void onCreate() {
        super.onCreate();
        setup();
    }

    private void setup() {
        RoboGuice.setBaseApplicationInjector(this, RoboGuice.DEFAULT_STAGE,
                RoboGuice.newDefaultRoboModule(this), new JSGuiceModule());
        RoboGuice.injectMembers(this,this);

        initApp.execute(JudgementSearcherApp.this);
    }
}

错误:

  

com.rudearts.judgementsearcher E / AndroidRuntime:FATAL EXCEPTION:main           java.lang.RuntimeException:无法创建应用程序com.rudearts.judgementsearcher.JudgementSearcherApp:com.google.inject.CreationException:Guice创建错误:           1)注入构造函数时出错,java.lang.NullPointerException                   at com.rudearts.judgementsearcher.core.managers.LawCaseManager。(Unknown Source)                   at com.rudearts.judgementsearcher.core.managers.LawCaseManager.class(Unknown Source)           找到com.rudearts.judgementsearcher.core.managers.LawCaseManager           for com.rudearts.judgementsearcher.controller.setup.commands.LoadLastUpdateDateCommand.lawCaseState(Unknown Source)           找到com.rudearts.judgementsearcher.controller.setup.commands.LoadLastUpdateDateCommand           for com.rudearts.judgementsearcher.controller.setup.commands.InitAppCommand.loadDate(Unknown Source)           找到com.rudearts.judgementsearcher.controller.setup.commands.InitAppCommand           for com.rudearts.judgementsearcher.JudgementSearcherApp.initApp(Unknown Source)                   在roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141)                   在roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141)           同时找到android.app.Application           for roboguice.util.Ln $ BaseConfig中的参数0。(未知来源)           同时找到roboguice.util.Ln $ BaseConfig           for roboguice.util.Ln.config中的字段(未知来源)           1错误                   在android.app.ActivityThread.handleBindApplication(ActivityThread.java:3291)                   在android.app.ActivityThread.access $ 2200(ActivityThread.java:121)                   在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:981)                   在android.os.Handler.dispatchMessage(Handler.java:99)                   在android.os.Looper.loop(Looper.java:130)                   在android.app.ActivityThread.main(ActivityThread.java:3770)                   at java.lang.reflect.Method.invokeNative(Native Method)                   在java.lang.reflect.Method.invoke(Method.java:507)                   在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:912)                   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)                   at dalvik.system.NativeStart.main(Native Method)            原因:com.google.inject.CreationException:Guice创建错误:           1)注入构造函数时出错,java.lang.NullPointerException                   at com.rudearts.judgementsearcher.core.managers.LawCaseManager。(Unknown Source)                   at com.rudearts.judgementsearcher.core.managers.LawCaseManager.class(Unknown Source)           找到com.rudearts.judgementsearcher.core.managers.LawCaseManager           for com.rudearts.judgementsearcher.controller.setup.commands.LoadLastUpdateDateCommand.lawCaseState(Unknown Source)           找到com.rudearts.judgementsearcher.controller.setup.commands.LoadLastUpdateDateCommand           for com.rudearts.judgementsearcher.controller.setup.commands.InitAppCommand.loadDate(Unknown Source)           找到com.rudearts.judgementsearcher.controller.setup.commands.InitAppCommand           for com.rudearts.judgementsearcher.JudgementSearcherApp.initApp(Unknown Source)                   在roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141)                   在roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141)           同时找到android.app.Application           for roboguice.util.Ln $ BaseConfig中的参数0。(未知来源)           同时找到roboguice.util.Ln $ BaseConfig           for roboguice.util.Ln.config中的字段(未知来源)           1错误                   在com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435)                   在com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:175)                   在com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)                   在com.google.inject.Guice.createInjector(Guice.java:95)                   在com.google.inject.Guice.createInjector(Guice.java:83)                   在roboguice.RoboGuice.setBaseApplicationInjector(RoboGuice.java:94)                   at com.rudearts.judgementsearcher.JudgementSearcherApp.setup(JudgementSearcherApp.java:26)                   at com.rudearts.judgementsearcher.JudgementSearcherApp.onCreate(JudgementSearcherA

1 个答案:

答案 0 :(得分:1)

好吧,伙计们,我自己找到了。

我在单例LawCaseManager中注入了util class,它是在创建应用程序期间注入的。我搜索了一些注射周期/无限循环或竞争条件,但没有发现任何明显的。

总而言之,当我在singleton类中删除注入时,一切都像往常一样。我搜索了我的旧项目,似乎我只将单例用于数据管理器,这些数据管理器持有应用状态,并且没有注入任何其他类。我很好奇,如果它只是特定的情况或是一些大规则,那个guice禁止在单身人士类内注射? :o