2014-10-07 44 views
0

我正在開發一個android應用程序,其中用戶信息存儲在雲數據庫(Parse),我正在使用這些值進行用戶標識。但是我無法在android if if語句中獲取用戶信息(用戶名&密碼)。請找到下面的代碼。用戶在Android上使用Parse登錄

private void userScreen() { 
       EditText username = (EditText) findViewById(R.id.userName); 
       String username1 = username.getText().toString(); 
       EditText password1 = (EditText) findViewById(R.id.password); 
       String userpassword = password1.getText().toString(); 
       ParseQuery<ParseObject> query = ParseQuery.getQuery("UserInfo"); 
       if ((query.whereEqualTo("user_name", username1);) && (query.whereEqualTo("password", userpassword));){ 

     } 
    } 

我得到錯誤如果聲明「& &」。「不是有效的解析操作

任何一個可以請給我提供了一個解決方案這個問題。

回答

1

這不是您稱爲Parse Queries的方式。如果你想兩個條件是真的,你會寫它像這樣:

ParseQuery<ParseObject> query = ParseQuery.getQuery("UserInfo"); 
query.whereEqualTo("user_name", username1); 
query.whereEqualTo("password", userpassword); 
query.findInBackground(new FindCallback<ParseObject>() { 
public void done(List<ParseObject> results, ParseException e) { 
    if (e == null) { 
     if (results.size() > 0) { 
      // query found a user 
     } 
    } else { 
     // error 
    } 
} 

我認爲更好的辦法是使用Parse Login功能。

ParseUser.logInInBackground("UserName", "Password", new LogInCallback() { 
    public void done(ParseUser user, ParseException e) { 
     if (user != null) { 
      // Hooray! The user is logged in. 
     } else { 
      // Signup failed. Look at the ParseException to see what happened. 
     } 
    } 
}); 
+0

我厭倦了使用你的代碼,但它沒有解決問題。 – coolDude 2014-10-07 22:04:45

+0

您仍然有錯誤訊息? – Dehli 2014-10-07 22:14:15

+0

不,不是錯誤消息,但我不能解決我的問題。我需要驗證用戶輸入並相應地打開新的活動。感謝您的幫助 – coolDude 2014-10-07 22:46:17

0

我認爲新德里的答案是正確的,但如果你要開始,如果另一個活動,讓我們假設用戶已經存在,那麼你就應該處理的其他條款在裏面

ParseUser.logInInBackground("UserName", "Password", new LogInCallback() { 
public void done(ParseUser user, ParseException e) { 
    if (user != null) { 
     // Hooray! The user is logged in. 
    } else { 
     // Signup failed. Look at the ParseException to see what happened. 
//here is where you should handle your stuffs. Look at the e.getMessage() or the errorID 
    } 
} 

}) ;