Question

This is weird. I used Roboguice 2.0 in all my recent projects with same libs and all seemd fine. I started brand new project and there came some creepy error out of (...) nowhere at the launch of my app. I searched everywhere, starting from SO, but all issues coresponding to this error where old or solutions didn't work.

Golden nail from Jaime Lannister's hand for answer to this nightmare!

I use Android Studio and 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

Class extending application:

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);
    }
}

Error:

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

Was it helpful?

Solution

Ok guys, I found it on my own.

I injected util class inside singleton LawCaseManager, which was injected during app creation. I searched for some injection cycles/endless loops or race conditions, but haven't found any obvious one.

All in all, when I removed injection inside singleton class, everything worked like always. I searched over my older projects and it appears, that I used singletons only for data managers, which were holding app state and none of them had injection of any other class. I am curious, if it was only specific case or is it some grand rule, that guice forbids injection inside singleton class? :O

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top