Bootstrap

android 获取设备id 崩溃,获取Android设备ID时出错

我正在尝试在我的Android应用中检索我的adroid设备的设备ID。但是,在我的程序中添加以下行后,错误存在并且程序无法启动:

String ts = Context.TELEPHONY_SERVICE;

TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(ts);

从logcat开始,它说问题来自第二行:

07-18 11:28:47.453: E/AndroidRuntime(5528): FATAL EXCEPTION: main

07-18 11:28:47.453: E/AndroidRuntime(5528): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{android.reader/android.reader.Reader}: java.lang.NullPointerException

07-18 11:28:47.453: E/AndroidRuntime(5528): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)

07-18 11:28:47.453: E/AndroidRuntime(5528): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)

07-18 11:28:47.453: E/AndroidRuntime(5528): at android.app.ActivityThread.access$600(ActivityThread.java:123)

07-18 11:28:47.453: E/AndroidRuntim

;