I’m using Handler and HandlerThread to perform asynchronous loading in my application, but something is going wrong, for example:
handler.postDelayed(new Runnable() {
@Override
public void run() {
.....................
}
}, 100);
this handler wrip (sic) in a new HandlerThread and is created in onCreate().
It seems like that is no problem, however there are times when an error appears, one example of this is a NullPointerException caused on this handler – it is stable before – but when I test on 2.1 version emulator this happen some times and I can’t solve it, is thee any one that can help me?
have you considered race conditions in your code? it sounds like the handler code is not performing proper synchonization – and might sometimes see changes from a different thread – which again causes your nullPointer exception.
try wrapping your problem code in a synchonized block – or if you are using primitve types only – move to volatile or atomic types.