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;
}
}