Thursday, August 7, 2014

NullPointerException when new PhoneStateListener

When I new PhoneStateListener() I am getting this error

  at android.os.Handler.<init>(
  at android.os.Handler.<init>(
  at android.telephony.PhoneStateListener$2.<init>(
  at android.telephony.PhoneStateListener.<init>(

I looked at the I believe the reason for this error is mQueue = looper.mQueue; so looper is null.  Only way to fix this problem is to call Looper.prepareMainLooper(); at the beginning of the process

1 comment:

  1. I have the exact same problem. Were do you exactly calls the prepareMainLooper()-method? I tried to call it before instantiating the PhoneStateListener, but I am getting an exception, claiming that only one Looper can exist per thread.