I am trying to get the unique device ID inside my Application class

public class ApplicationClass extends Application

    public ApplicationClass()
        TelephonyManager mTelephonyMgr =
        deviceID = mTelephonyMgr.getDeviceId();

My code will run right until it gets to creating the telephony manager
instance but will not actually create it and it throws a
NullPointerException (I think).

Is there something I'm doing wrong?  Do I have to create a context and
call getSystemService(...) with context.getSystemService(...)?

I also get the same error when I comment those two lines out and try
to get the LocationManager:

locationManager =

Same exact error happens.   Am I only allowed to call getSystemService
inside of an Activity class because I've tried calling it in a Service
and of course Application with no luck.

Any help is appreciated.

You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at

To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to