Take this base class:
public abstract class XMPPSubservice
{
protected XMPPService mTheService;
protected XMPPSubservice(Context context)
{
Intent intent = new Intent(context, XMPPService.class);
context.startService(intent);
}
public void onServiceInstance(XMPPService service) {
// TODO Auto-generated method stub
mTheService = service;
}
}
And this derived class:
public class PublicDataSubservice extends XMPPSubservice
{
private final SomeObject mObj = new SomeObject();
public PublicDataSubservice(Context context) {
super(context);
}
@Override
public void onServiceInstance(XMPPService service)
{
super.onServiceInstance(service);
mObj.doSomethingWith(mTheService);
}
}
The goal was to only call mObj.doSomethingWith(mTheService); after the mTheService became valid (which happened in the base class). Thing was it always spat out NPE at the mObj line. I can understand why that happened, but it looks wonky to me. So is this a bug or a feature of DVM ? How about JVM ?