SharedPreferences を使用してログイン資格情報を保存するコードを試しています。資格情報が正常に保存されていると信じていますが、編集中の資格情報と保存されている資格情報を比較してログインしようとすると. 「パスワードが違います」というエラーが繰り返し表示されます。私が見落としているものがわからない。ログインするためのコードは以下です。
ログイン:
   public class AccessApp extends Activity implements OnClickListener {
private SharedPreferences sp;
String user,pass;
Button lBttn,cBttn;
EditText uname,pword;
Intent i;
int flag=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{ 
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    lBttn=(Button)findViewById(R.id.login_button);
    cBttn=(Button)findViewById(R.id.cancel_button);
    uname=(EditText)findViewById(R.id.username);
    pword=(EditText)findViewById(R.id.password);
    lBttn.setOnClickListener(this);
    cBttn.setOnClickListener(this);
}
public void onClick(View arg0) {
    sp=this.getSharedPreferences("Register", MODE_WORLD_READABLE);
    user=sp.getString("USERNAME", "");
    pass=sp.getString("PASSWORD","");
    if(lBttn==arg0){
            if((uname.getText().toString().compareTo(user)==0)&& 
               (pword.getText().toString().compareTo(pass)==0))
            {
          Toast.makeText(this, "You are Logged In", 20000).show();
               Intent intent;
               intent=new Intent(this,details.class);
               startActivity(intent);
              flag=1;
            }
        else
           {
            Toast.makeText(this, "Wrong Username or Password",20000).show();
            flag=0;   
           }       
        } 
登録:
     public class SharedPrefLoginActivity extends Activity implements OnClickListener {
private SharedPreferences sp;
Intent i;
Button regBttn,rtnBttn;
EditText rName,rPwd;
String user,pass,cpass,chk;
String stat="a";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);
    rName=(EditText)findViewById(R.id.reg_uname);
    rPwd=(EditText)findViewById(R.id.reg_pswd);
    regBttn=(Button)findViewById(R.id.reg_button);
    rtnBttn=(Button)findViewById(R.id.rtn_button); 
    regBttn.setOnClickListener(this);
    rtnBttn.setOnClickListener(this);
    sp=this.getSharedPreferences("AccessApp", MODE_WORLD_READABLE);
    chk=sp.getString("USERNAME", "");
    if(chk.length()!=0){
        sp=getSharedPreferences("AccessApp",MODE_WORLD_WRITEABLE); 
        i=new Intent(this,AccessApp.class);
        startActivity(i);      
    }
}
public void onClick(View arg0) {
    user=rName.getText().toString();
    pass=rPwd.getText().toString();
    if(arg0==regBttn){
        if((user.length()!=0))
        {
            if((pass.length()!=0))
            {
        sp=getSharedPreferences("AccessApp",MODE_WORLD_WRITEABLE);
        Editor myEditor=sp.edit();
        myEditor.putString("USERNAME", user);
        myEditor.putString("PASSWORD", pass);
        myEditor.commit();
        Toast.makeText(this, "Registration is successfull",10000).show();
        i=new Intent(this,AccessApp.class);
        startActivity(i);
        }
        else
         {
          Toast.makeText(this, "Please Enter password", 10000).show();  
         }
         }
        else{
            Toast.makeText(this,"Please Enter Username",10000).show();
         }
      }