我真的不确定为什么会这样。似乎 getLine1Number 没有被实例化 - 但似乎第二次引用它不需要它(当我注释掉空检查时它不会引发错误。
在职的:
public class StartActivity extends Activity implements OnClickListener {
Button goButton;
Context c;
boolean isAirPlaneMode, isMDNPresent = false;//boolean values to check for airplane mode and if the sim populates the MDN
int simState;
TelephonyManager tm;
boolean NetworkConnection = false;//boolean to check the Network Availability
AlertDialog mConfirmAlert = null;
TextView text;
TextView mUpdatetext;
int version;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
version = android.os.Build.VERSION.SDK_INT;
tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// to read the SIM state
simState = tm.getSimState();
System.out.println("Sim State" + simState);
//if (tm.getLine1Number = null) {
//isMDNPresent = true;
//}
// to check for MDN
if (tm.getLine1Number().equalsIgnoreCase("")) {
isMDNPresent = true;
}
抛出错误:getLine1Number 无法解析或不是字段
public class StartActivity extends Activity implements OnClickListener {
Button goButton;
Context c;
boolean isAirPlaneMode, isMDNPresent = false;//boolean values to check for airplane mode and if the sim populates the MDN
int simState;
TelephonyManager tm;
boolean NetworkConnection = false;//boolean to check the Network Availability
AlertDialog mConfirmAlert = null;
TextView text;
TextView mUpdatetext;
int version;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
version = android.os.Build.VERSION.SDK_INT;
tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// to read the SIM state
simState = tm.getSimState();
System.out.println("Sim State" + simState);
if (tm.getLine1Number = null) {
isMDNPresent = true;
}
// to check for MDN
if (tm.getLine1Number().equalsIgnoreCase("")) {
isMDNPresent = true;
}