我對Java和Android開發相當陌生。我正在爲我的網站製作一個應用程序。我正在使用Retrofit
連接到我的REST Web服務。無法更改來自匿名類的變量
以下是我用來遍歷客戶ID和每個ID的一段代碼,我們打電話來檢索與ID相關的電子郵件。 authenticateUser
方法接收用戶名,密碼和ID列表(Customer ID)。 ID位於mywebsite/api/customers。 的電子郵件可在mywebsite/API /客戶/ ID
public class Authentication {
private static String receivedEmail;
public static boolean authenticateUser(List<Integer> ids, final String username, String pass) {
RestAdapter adapter = new RestAdapter.Builder().setEndpoint(MainActivity.ENDPOINT).build();
AuthenticationUsernameAPI api = adapter.create(AuthenticationUsernameAPI.class);
final boolean[] found = {false};
for (Integer id: ids) {
if (!found[0]) {
api.getUserEmail(id.toString(), new Callback<CustomerLoginEmail>() {
@Override
public void success(CustomerLoginEmail customerLoginEmail, Response response) {
receivedEmail = customerLoginEmail.getCustomer().getEmail().toString();
if (receivedEmail.compareTo(username) == 0) {
found[0] = true;
}
}
@Override
public void failure(RetrofitError error) {
Log.d("ERROR", error.getMessage());
}
});
} else {
return true;
}
}
return false;
}
}
的方法authenticateUser
總是返回false。請幫忙