I have a problem with my android app, it crushes every time i run it. The error seems to be java.lang.NullPointerException. Here is the error.enter image description here
The error is java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.retrofitexample.models.DefaultResponse.getFail()' on a null object reference at com.example.retrofitexample.activities.RegisterActivity$3.onResponse(RegisterActivity.java:124)
the code at register activity is:-
Call<DefaultResponse> call = retrofitClient
.getInstance()
.getInterfaceApi()
.registerUser(name, email, password);
call.enqueue(new Callback<DefaultResponse>() {
@Override
public void onResponse(Call<DefaultResponse> call, Response<DefaultResponse> response) {
DefaultResponse dr = response.body();
if (response.code() == 201) {
Toast.makeText(RegisterActivity.this, dr.getSuccess(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(RegisterActivity.this, dr.getFail(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<DefaultResponse> call, Throwable t) {
}
});
i tried changing few lines of code but nothing seems to work. Help please
Try using Fast Android Networking library, it's very simple and good way to work with PHP or Laravel.