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 {
private static Session session;
public Session getSession() {
if (session == null){
session = new Session();
}
return session;
}
}
--
public class ChannelManager {
@Inject SessionService sessionService;
public String getName(){
return sessionService.getSession().getName();
}
}
public class MainActivity extends RoboActivity{
@InjectView(R.id.button1) Button btn;
@Inject SessionService a;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a.getSession().setName("dsadas");
Log.i("A","NEW: "+ a.getSession().getName());
Log.i("A","NEW NAME: "+ new ChannelManager().getName());
}
I get null exception on "new ChannelManager().getName()" line. What's wrong with that? Thanks in advance.