打破;我的最后休息;给我一个:无法访问的语句错误,任何线索为什么?

时间:2015-10-11 02:54:30

标签: java break

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    initBT();
    initNFC();
    StartApp();
}
private void initBT() {
    mBTState = BTModule.GetInstance().initBT(); //trying to get the BT adapter 
    if(mBTState.equals(eBluetoothStatus.BT_DISABLED)){ //if adapter is not enabled
        Intent enableBtIntent = new Intent(BTModule.GetAdapter().ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }
}

private void initNFC(){
    mNFCState = NFCModule.initNFC(getApplicationContext());
    if(mNFCState == eNFCStatus.NFC_NOT_SUPPORTED){
        UIUtils.getInstance().Toast(this, "NFC is not suppoeted for this device");
        //Toast.makeText(this, "NFC is not suppoeted for this device", Toast.LENGTH_LONG).show();
    }
    else if(mNFCState == eNFCStatus.NFC_DISABLED){
        Intent nfcIntent;
        if(android.os.Build.VERSION.SDK_INT >= 16){
            nfcIntent = new Intent(android.provider.Settings.ACTION_NFC_SETTINGS);  
        }
        else{
        nfcIntent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
        }
        startActivityForResult(nfcIntent,REQUEST_ENABLE_NFC);
        UIUtils.getInstance().Toast(this, "Please enable NFC");
        //Toast.makeText(this, "Please enable NFC", Toast.LENGTH_LONG);
    }
    else{
        Toast.makeText(this, "NFC is up and running", Toast.LENGTH_LONG).show();
    }
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == REQUEST_ENABLE_BT){
        if(resultCode == RESULT_CANCELED)
        {
            Toast.makeText(this, "This app needs bluetooth", Toast.LENGTH_LONG).show();
            finish();
        }
        else if (resultCode == RESULT_OK) {
            Toast.makeText(this, "Bluetooth enabled", Toast.LENGTH_LONG).show();
        }

    }
    else if(requestCode == REQUEST_ENABLE_NFC){
        if(resultCode == RESULT_OK){
            Toast.makeText(this, "NFC enabled", Toast.LENGTH_LONG).show();
            }
        else if(resultCode == RESULT_CANCELED)
        {
            Toast.makeText(this, "This app needs NFC to be enabled", Toast.LENGTH_LONG).show();
            finish();
        }

    }
}


private void StartApp(){
    Intent nextIntent;

    if(SaveSharedPreference.getUserName(MainActivity.this).length() == 0)
    {
        nextIntent = new Intent(MainActivity.this, LoginActivity.class);
    }
    else
    {
        nextIntent = new Intent(MainActivity.this, MainMenuActivity.class);
    }   
    startActivity(nextIntent);
    finish();
}

这个代码已经工作了大约三天,我有三个版本正在尝试。到目前为止,这是我最喜欢和最复杂但比其他更有效的。 *在他人的帮助下。但是为什么我会得到这个:无法访问的语句错误?

1 个答案:

答案 0 :(得分:1)

在最后一个while循环中

    if (keyboard.hasNextDouble() && (balance = keyboard.nextDouble()) > 0);

并且表达式结尾处的分号会导致错误 - 你在那里有一个空的 if body ,而且(我猜)应该在条件下的每一个中断时间使得结束代码无法访问