なぜこれが起こっているのか本当にわかりません。getLine1Number がインスタンス化されていないように見えますが、それへの 2 番目の参照はそれを必要としないようです (null チェックをコメントアウトしてもエラーはスローされません。
働く:
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;
}
THROWS ERROR: 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;
}