You declare timer but initialize it to null. What do you expect to happen? This is going to cause a NullPointerException every time.