我正在嘗試使用以下代碼讀取設備的電話號碼。當電話號碼不可用時,我閱讀訂閱者ID。它在一些手機中工作,並在某些設備中拋出NULL指針異常。該設備日誌顯示我收到NULL指針異常以下行讀取設備電話號碼拋出NULLPointerException
if(MyPhoneNumber.equals(""))
請讓我知道如何使它在所有的設備上運行。
TelephonyManager tMgr =(TelephonyManager)ShowMyLocation.this.getSystemService(Context.TELEPHONY_SERVICE);
String MyPhoneNumber = tMgr.getLine1Number();
if(MyPhoneNumber.equals(""))
MyPhoneNumber = tMgr.getSubscriberId();
可能重複的[獲取電話號碼問題](http://stackoverflow.com/questions/5134398/get-phone-number-problem) – 2012-07-18 05:07:49