Возьми этот базовый класс:
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;
}
}
И этот производный класс:
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);
}
}
Целью было вызвать только mObj.doSomethingWith (mTheService); после того, как mTheService вступил в силу (что произошло в базовом классе). Дело в том, что он всегда выплевывал NPE на линии mObj. Я могу понять, почему это произошло, но для меня это выглядит странно. Так это ошибка или особенность DVM? Как насчет JVM?