gpt4 book ai didi

java - Roboguice 在启动时崩溃应用程序

转载 作者:行者123 更新时间:2023-11-30 02:54:38 28 4
gpt4 key购买 nike

这很奇怪。我在最近的所有具有相同库的项目中都使用了 Roboguice 2.0,一切似乎都很好。我开始了全新的项目,但在我的应用程序启动时,(...) 出现了一些令人毛骨悚然的错误。我到处搜索,从 SO 开始,但所有问题都对应于旧的或解决方案不起作用的错误。

Jaime Lannister 手中的金钉为这场噩梦提供了答案!

我使用 Android Studio 和库:

- 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: Unable to create application com.rudearts.judgementsearcher.JudgementSearcherApp: com.google.inject.CreationException: Guice creation errors: 1) Error injecting constructor, java.lang.NullPointerException at com.rudearts.judgementsearcher.core.managers.LawCaseManager.(Unknown Source) at com.rudearts.judgementsearcher.core.managers.LawCaseManager.class(Unknown Source) while locating com.rudearts.judgementsearcher.core.managers.LawCaseManager for field at com.rudearts.judgementsearcher.controller.setup.commands.LoadLastUpdateDateCommand.lawCaseState(Unknown Source) while locating com.rudearts.judgementsearcher.controller.setup.commands.LoadLastUpdateDateCommand for field at com.rudearts.judgementsearcher.controller.setup.commands.InitAppCommand.loadDate(Unknown Source) while locating com.rudearts.judgementsearcher.controller.setup.commands.InitAppCommand for field at com.rudearts.judgementsearcher.JudgementSearcherApp.initApp(Unknown Source) at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141) at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141) while locating android.app.Application for parameter 0 at roboguice.util.Ln$BaseConfig.(Unknown Source) while locating roboguice.util.Ln$BaseConfig for field at roboguice.util.Ln.config(Unknown Source) 1 error at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3291) at android.app.ActivityThread.access$2200(ActivityThread.java:121) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3770) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670) at dalvik.system.NativeStart.main(Native Method) Caused by: com.google.inject.CreationException: Guice creation errors: 1) Error injecting constructor, java.lang.NullPointerException at com.rudearts.judgementsearcher.core.managers.LawCaseManager.(Unknown Source) at com.rudearts.judgementsearcher.core.managers.LawCaseManager.class(Unknown Source) while locating com.rudearts.judgementsearcher.core.managers.LawCaseManager for field at com.rudearts.judgementsearcher.controller.setup.commands.LoadLastUpdateDateCommand.lawCaseState(Unknown Source) while locating com.rudearts.judgementsearcher.controller.setup.commands.LoadLastUpdateDateCommand for field at com.rudearts.judgementsearcher.controller.setup.commands.InitAppCommand.loadDate(Unknown Source) while locating com.rudearts.judgementsearcher.controller.setup.commands.InitAppCommand for field at com.rudearts.judgementsearcher.JudgementSearcherApp.initApp(Unknown Source) at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141) at roboguice.config.DefaultRoboModule.configure(DefaultRoboModule.java:141) while locating android.app.Application for parameter 0 at roboguice.util.Ln$BaseConfig.(Unknown Source) while locating roboguice.util.Ln$BaseConfig for field at roboguice.util.Ln.config(Unknown Source) 1 error at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:435) at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:175) at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109) at com.google.inject.Guice.createInjector(Guice.java:95) at com.google.inject.Guice.createInjector(Guice.java:83) at roboguice.RoboGuice.setBaseApplicationInjector(RoboGuice.java:94) at com.rudearts.judgementsearcher.JudgementSearcherApp.setup(JudgementSearcherApp.java:26) at com.rudearts.judgementsearcher.JudgementSearcherApp.onCreate(JudgementSearcherA

最佳答案

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

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

总而言之,当我在单例类中删除注入(inject)时,一切都像往常一样工作。我搜索了我的旧项目,似乎我只将单例用于数据管理器,它们保持应用程序状态并且没有任何其他类的注入(inject)。我很好奇,如果这只是特定情况或者是一些重要规则,那么 guice 禁止在单例类中注入(inject)? :O

关于java - Roboguice 在启动时崩溃应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23505367/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com