简体   繁体   English

使用 retrofit 登录:(android 中的 500 内部错误)

[英]Login with retrofit: (500 internal error in android)

I create login with spring boot api.我使用 spring 引导 api 创建登录。 When I try in postman, the server work fine.当我在 postman 中尝试时,服务器工作正常。 But when I tried to implement in my android app, it going failed.但是当我尝试在我的 android 应用程序中实现时,它失败了。 It's keep me the error 500 in android and java.lang.NullPointerException: null in my server.它让我在我的服务器中的 android 和 java.lang.NullPointerException: null 中出现错误 500。 Can some one help me?有人能帮我吗?

Logcat日志猫

06-24 19:32:31.490 15836-15836/com.test.restapitest E/errorResponse: {"timestamp":"2020-06-24T12:32:29.402+00:00","status":500,"error":"Internal Server Error","message":"","path":"/user/login"}

Model Model

public class User {

    @SerializedName("id")
    @Expose
    private int id;

    @SerializedName("email")
    @Expose
    private String email;

    @SerializedName("password")
    @Expose
    private String password;
}

Interface界面

public interface ApiInterface {

    @POST("/user/login")
    Call<User> login(@Body User user);
}

This is the login method in my activity这是我活动中的登录方法

public void getLogin(User user){
    ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
    Call<User> call = apiService.login(user);

    call.enqueue(new Callback<User>() {
        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            User user = new User();
            String email = etEmail.getText().toString();
            String password = etPassword.getText().toString();
            if((email.equals(user.getEmail()) && password.equals(user.getPassword())){
                Intent intents = new Intent(UserActivity.this, MainActivity.class);
                startActivity(intents);
            }else{
                Snackbar.make(nestedScrollView, getString(R.string.error_valid_email_password), Snackbar.LENGTH_LONG).show();
            }

        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
            Log.d("TAG","Response = "+t.toString());
        }
    });

I create login with spring boot api.我使用 spring 引导 api 创建登录。 When I try in postman, the server work fine.当我在 postman 中尝试时,服务器工作正常。 But when I tried to implement in my android app, it going failed.但是当我尝试在我的 android 应用程序中实现时,它失败了。 It's keep me the error 500 in android and java.lang.NullPointerException: null in my server.它让我在我的服务器中的 android 和 java.lang.NullPointerException: null 中出现错误 500。 Can some one help me?有人能帮我吗?

Logcat日志猫

06-24 19:32:31.490 15836-15836/com.test.restapitest E/errorResponse: {"timestamp":"2020-06-24T12:32:29.402+00:00","status":500,"error":"Internal Server Error","message":"","path":"/user/login"}

Model Model

public class User {

    @SerializedName("id")
    @Expose
    private int id;

    @SerializedName("email")
    @Expose
    private String email;

    @SerializedName("password")
    @Expose
    private String password;
}

Interface界面

public interface ApiInterface {

    @POST("/user/login")
    Call<User> login(@Body User user);
}

This is the login method in my activity这是我活动中的登录方法

public void getLogin(User user){
    ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
    Call<User> call = apiService.login(user);

    call.enqueue(new Callback<User>() {
        @Override
        public void onResponse(Call<User> call, Response<User> response) {
            User user = new User();
            String email = etEmail.getText().toString();
            String password = etPassword.getText().toString();
            if((email.equals(user.getEmail()) && password.equals(user.getPassword())){
                Intent intents = new Intent(UserActivity.this, MainActivity.class);
                startActivity(intents);
            }else{
                Snackbar.make(nestedScrollView, getString(R.string.error_valid_email_password), Snackbar.LENGTH_LONG).show();
            }

        }

        @Override
        public void onFailure(Call<User> call, Throwable t) {
            Log.d("TAG","Response = "+t.toString());
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM