i used retrofit to call the api and it work fine in debug but when i create a release apk it crash with null pointer Exception i can't know why in the release
here is the log file in the release apk
2020-05-28 10:29:37.680 7935-7935/com.sideeg.afia_user E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sideeg.afia_user, PID: 7935
java.lang.NullPointerException: throw with null exception
at com.sideeg.afia_user.activates.LoginActivity$b.a(:84)
at i.i$b$a.a(:82)
at i.a.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
this the api declare
@FormUrlEncoded
@POST("api/users/login")
Call<LoginResponse> register(@Field("name") String name, @Field("phone") String mobile);
this the Login Model
public class LoginResponse {
@SerializedName("data")
private LoginData data;
@SerializedName("error")
private Boolean error;
@SerializedName("message")
private String message;
public LoginData getData() {
return data;
}
public void setData(LoginData data) {
this.data = data;
}
public Boolean getError() {
return error;
}
public void setError(Boolean error) {
this.error = error;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
login data
public class LoginData {
@SerializedName("id")
private String id;
@SerializedName("name")
private String name;
@SerializedName("phone")
private String phone;
@SerializedName("otp")
private String otp;
@SerializedName("created_at")
private String created_at;
@SerializedName("updated_at")
private String updated_at;
@SerializedName("email")
private String email;
@SerializedName("email_verified_at")
private String email_verified_at;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getOtp() {
return otp;
}
public void setOtp(String otp) {
this.otp = otp;
}
public String getCreated_at() {
return created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
public String getUpdated_at() {
return updated_at;
}
public void setUpdated_at(String updated_at) {
this.updated_at = updated_at;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getEmail_verified_at() {
return email_verified_at;
}
public void setEmail_verified_at(String email_verified_at) {
this.email_verified_at = email_verified_at;
}
}
here is the api response from the postman
{
"error": false,
"data": {
"id": 4,
"name": "isra ahemd",
"phone": "999005491",
"otp": 1188,
"created_at": "2020-05-22T17:31:32.000000Z",
"updated_at": "2020-05-28T08:04:47.000000Z",
"email": null,
"email_verified_at": null
},
"message": "please verify your number with this code 1188"
}
and here is the method in loginActivity which make the crash exactly here (if (response.body() != null ? response.body().getError() : true){)
private void register(final String name,final String phone) {
loading = ProgressDialog.show(LoginActivity.this, getString(R.string.loading), getString(R.string.wait), false, false);
loading.setCancelable(false);
loading.setCanceledOnTouchOutside(false);
NetWorkApis netWorkApis = ApiClient.getClient(ApiClient.BASE_URL).create(NetWorkApis.class);
Call<LoginResponse> settingResponseCall = netWorkApis.register(name,phone);
settingResponseCall.enqueue(new Callback<LoginResponse>() {
@SuppressLint("LongLogTag")
@Override
public void onResponse(@NotNull Call<LoginResponse> call, @NotNull Response<LoginResponse> response) {
if (response.isSuccessful()) {
Log.i(TAG,"respnse : "+ response.toString());
Log.i(TAG,"respnse body : "+ response.body());
Log.i(TAG,"respnse message : "+ response.message());
Log.i(TAG,"respnse message : "+ response.errorBody());
if (response.body() != null ? response.body().getError() : true){
Utility.showAlertDialog(getString(R.string.error), response.body().getMessage(), LoginActivity.this);
loading.dismiss();
}else {
LocalSession localSession = new LocalSession(getApplicationContext());
localSession.createSession(Boolean.TRUE,response.body().getData().getName(),response.body().getData().getPhone(),
Integer.valueOf(response.body().getData().getId()),response.body().getData().getOtp());
loading.dismiss();
startActivity(new Intent(getApplicationContext(),OTPActivity.class));
finish();
}
}else {
Log.i(TAG, response.errorBody() != null ? response.errorBody().toString() : "response is null");
Utility.showAlertDialog(getString(R.string.error), getString(R.string.servererror), LoginActivity.this);
loading.dismiss();
}
}
@SuppressLint("LongLogTag")
@Override
public void onFailure(@NotNull Call<LoginResponse> call, @NotNull Throwable t) {
Log.i(TAG, t.getLocalizedMessage());
loading.dismiss();
Utility.showAlertDialog(getString(R.string.error), getString(R.string.servererror), LoginActivity.this);
}
});
}
**please note that the app is worked fine in the debug apk this problem is just in the release **