祝酒词不工作,否则如果

toast not working and also else if

此代码中的 else if 部分无效。如果登录失败,toast 不会出现。

我的代码

try {
    s= json.getString("info");
    Log.d("Msg", json.getString("info"));
    if(s.equals("success")) {
        Intent login = new Intent(getApplicationContext(),MainPage.class);
        login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(login);                    
        finish();            
    } else if(s.equals("fail")) { 
        Toast.makeText(getParent(),"Login Failed",
        Toast.LENGTH_SHORT).show();
        ((EditText) findViewById(R.id.user)).setText("");
        ((EditText) findViewById(R.id.pwd)).setText("");
        finish();
    }

尝试改变这个:

Toast.makeText(getParent(),"Login Failed", Toast.LENGTH_SHORT).show();

收件人:

Toast.makeText(getApplicationContext(), "Login Failed", Toast.LENGTH_SHORT).show();