Skip to content Skip to sidebar Skip to footer

What Is Wrong With Roboguice

I want to create a singleton object using RoboGuice but I get null exception. I don't know what is wrong with my codes. @Singleton public class SessionService { p

Solution 1:

When you do new ChannelManager(), you are not using Guice injection, so your injected fields are null.

To inject your ChannelManager, either use the @Inject annotation or use the following code to create your instance:

ChannelManager myChannelManager = RoboGuice.getInjector(this).getInstance(ChannelManager.class);

Solution 2:

Also consider if there is necessity to use 'new' operator to create e Object. This always implicate some problems especially in (unit)tests.

Post a Comment for "What Is Wrong With Roboguice"