AWS:身份验证处理程序java.lang.AbstractMethodError:

时间:2017-04-09 06:18:53

标签: android aws-cognito

我在这里遵循教程:

http://docs.aws.amazon.com/cognito/latest/developerguide/tutorial-integrating-user-pools-android.html

这是我的代码:

import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationContinuation;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.AuthenticationDetails;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.MultiFactorAuthenticationContinuation;
import com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler;
import umbc.edu.helpers.AppHelper;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

EditText username, password;
Button login;
TextView create_acount;
String username_, password_;

String TAG = "MainActivity.class";

protected String tag = "MainActivity";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.w(tag, "onCreate()");
    setContentView(R.layout.activity_main);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    username = (EditText) findViewById(R.id.username);
    password = (EditText) findViewById(R.id.password);
    login = (Button) findViewById(R.id.login_button);
    login.setOnClickListener(this);
    create_acount = (TextView) findViewById(R.id.create_account);
    create_acount.setOnClickListener(this);

}

@Override
protected void onPause() {
    super.onPause();
    Log.w(tag, "onPause()");
}

@Override
protected void onResume() {
    super.onResume();
    Log.w(tag, "onResume()");
}

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.w(tag, "onDestroy()");
}

@Override
protected void onStart() {
    super.onStart();
    Log.w(tag, "onStart()");
}

@Override
protected void onStop() {
    super.onStop();
    Log.w(tag, "onStop()");
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.login_button:
            username_ = username.getText().toString();
            password_ = password.getText().toString();

            if (!username_.matches("") && !password_.matches("")) {
                AppHelper.init(getApplicationContext());
                AppHelper.getPool().getUser(username_).getSessionInBackground(authenticationHandler);
            }
            break;
        case R.id.create_account:
            Intent intent = new Intent(this, CreateAccountActivity.class);
            startActivity(intent);
            break;
    }
}

AuthenticationHandler authenticationHandler = new AuthenticationHandler() {

    @Override
    public void onSuccess(CognitoUserSession cognitoUserSession) {
        Log.d(TAG, "Auth Success");
        AppHelper.setCurrSession(cognitoUserSession);

        //Go To Home Activity
        startActivity(new Intent(MainActivity.this, HomeActivity.class));
    }

    @Override
    public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String username) {
        // The API needs user sign-in credentials to continue
        AuthenticationDetails authenticationDetails = new AuthenticationDetails(username_, password_, null);

        // Pass the user sign-in credentials to the continuation
        authenticationContinuation.setAuthenticationDetails(authenticationDetails);

        // Allow the sign-in to continue
        authenticationContinuation.continueTask();
    }

    @Override
    public void getMFACode(MultiFactorAuthenticationContinuation multiFactorAuthenticationContinuation) {
        Toast.makeText(MainActivity.this, "GET MFA CODE CALLED", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onFailure(Exception e) {
        Toast.makeText(MainActivity.this, "Failed" + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
    }
};
}

我收到以下错误:

04-09 01:56:42.557 16494-16494/umbc.edu.app E/AndroidRuntime: FATAL EXCEPTION: main
                                                          Process: umbc.edu.app, PID: 16494
                                                          java.lang.AbstractMethodError: abstract method "void com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler.onSuccess(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserSession, com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)"
                                                              at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser$5$1.run(CognitoUser.java:639)
                                                              at android.os.Handler.handleCallback(Handler.java:739)
                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                              at android.os.Looper.loop(Looper.java:145)
                                                              at android.app.ActivityThread.main(ActivityThread.java:6862)
                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                              at java.lang.reflect.Method.invoke(Method.java:372)
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

我该如何解决这个问题?好像它正在使用不同的库。

1 个答案:

答案 0 :(得分:0)

我明白了。

我有一个带有AWS jar文件的libs文件夹,但我的gradle.build文件中也有以下内容:

compile 'com.amazonaws:aws-android-sdk-core:2.2.+'
compile 'com.amazonaws:aws-android-sdk-ddb:2.2.+'
compile 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.2.+'

我刚删除了那些,一切都很好