-1

我真的不确定为什么会这样。似乎 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;
        }
4

3 回答 3

0

它应该是

    if (tm.getLine1Number() == null) {

注意()

于 2013-10-11T17:21:40.170 回答
0

在工作部分,它是一种方法

if (tm.getLine1Number().

在非工作代码中,它用作变量(no“()”)

if (tm.getLine1Number = null)

你也想比较不初始化所以改变它

if (tm.getLine1Number = null)

if (tm.getLine1Number() == null)

添加额外的“=”

于 2013-10-11T17:21:51.427 回答
0

首先,您编写 'tm.getLine1Number = null' 就好像它是一个字段一样。其次,您编写了 'tm.getLine1Number().equalsIgnoreCase("") ,就好像它是一种方法一样。这就是为什么一个工作而一个不工作的原因。

于 2013-10-11T17:23:57.593 回答