Problem z aktualizacją hasła

0

Próbuje zaktualizować hasło ale wyskakuję mi błąd i wywala z aplikacji po wciśnięciu buttona: <java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.barry.crm.models.DefaultResponse.getMsg()' on a null object reference>. Aktualizacja hasła działa poprzez postmena tzn zaktualizuje hasło gdy jest wszystko ok natomiast gdy coś jest nie tak to rzuca odpowiedni błąd

 private void updatePassword(){
String currentpassword = editTextCurrentPassword.getText().toString().trim();
        String newpassword = editTextNewPassword.getText().toString().trim();

        if (currentpassword.isEmpty()) {
            editTextCurrentPassword.setError("Podaj aktualne hasło");
            editTextCurrentPassword.requestFocus();
            return;
        }

        if (newpassword.isEmpty()) {
            editTextNewPassword.setError("Podaj nowe hasło");
            editTextNewPassword.requestFocus();
            return;
        }


        User user = SharedPrefManager.getInstance(getActivity()).getUser();
        Call<DefaultResponse> call = RetrofitClient.getInstance()
                .getApi().updatePassword(
                        user.getEmail(),
                        currentpassword,
                        newpassword
                );
        call.enqueue(new Callback<DefaultResponse>() {
            @Override
            public void onResponse(Call<DefaultResponse> call, Response<DefaultResponse> response) {
                Toast.makeText(getActivity(), response.body().getMsg(), Toast.LENGTH_LONG).show();


            }

            @Override
            public void onFailure(Call<DefaultResponse> call, Throwable t) {

            }
        });
}

Fragment z Api:

  @FormUrlEncoded
    @PUT("updatepassword")
    Call<DefaultResponse> updatePassword(
            @Field("Email") String Email,
            @Field("currentpassword") String currentpassword,
            @Field("newpassword") String newpassword

    );

i Klasa DefaultResponse:

public class DefaultResponse {
    @SerializedName("error")
    private boolean err;
    @SerializedName("message")
    private String msg;
    public DefaultResponse(boolean err, String msg) {
        this.err = err;
        this.msg = msg;
    }
    public boolean isErr() {
        return err;
    }
    public String getMsg() {
        return msg;
    }
}
0

wklej caly stacktrace
masz podpiety okhttp + gson albo jakis moshi do retrofita?
podepnij okhttp loger i zobacz co przychodzi w response

0
pozdroooo2 napisał(a):

wklej caly stacktrace
masz podpiety okhttp + gson albo jakis moshi do retrofita?
podepnij okhttp loger i zobacz co przychodzi w response

Mam converter gsona jak widać poniżej

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitClient {

    private static final String BASE_URL = "http://192.168.1.125/crm/public/";
    private static RetrofitClient mInstance;
    private Retrofit retrofit;

    private RetrofitClient() {
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public static synchronized RetrofitClient getInstance() {
        if (mInstance == null) {
            mInstance = new RetrofitClient();
        }
        return mInstance;
    }

    public Api getApi(){
        return retrofit.create(Api.class);
    }
}

a tutaj stacktrace:
https://ibb.co/pK53B6t

0

Udało mi się naprawić błąd z wywalaniem aplikacji natomiast teraz ciągle wyskakuje mi że podałem niepoprawne hasło

0

Problem rozwiązany udało się wszystko zrobić

0

Dodałem coś takiego do AllUsersActivity ale dalej brak rezultatów

private void generateRole() {
        final Role role = SharedPrefManager.getInstance(AllUsersActivity.this).getRole();
        Call<RolesResponse> call = RetrofitClient.getInstance().getApi().getAllRoles();

        call.enqueue(new Callback<RolesResponse>() {
            @Override
            public void onResponse(Call<RolesResponse> call, Response<RolesResponse> response) {

                roleList = response.body().getAllRoles();
            }

            @Override
            public void onFailure(Call<RolesResponse> call, Throwable t) {

            }


        });

1 użytkowników online, w tym zalogowanych: 0, gości: 1