Nukhba Arshad Nukhba Arshad - 2 months ago 14
Android Question

Am getting null point exception at retrofit onResponse method

my Json:

"status": "1",
"login": "sucess"

this is my model class:

public class LoginModel {

private String status;

private String login;

this is my interface:

public interface RestInterface {

String url = "";

Call<LoginModel> Login(@Field("email") String email,
@Field("pass") String passs);

this is my call method:

Retrofit retrofit = new Retrofit.Builder()
//Creating Rest Services
final RestInterface restInterface = retrofit.create(RestInterface.class);

//Calling method to get check login
Call<LoginModel> response = restInterface.Login(Email.getText().toString(), Password.getText().toString());
response.enqueue(new Callback<LoginModel>() {
public void onResponse(Response<LoginModel> response, Retrofit retrofit) {


LoginModel lm = response.body();

if ( lm.getStatus().equals("1")) { //login Success

Toast.makeText(LoginActivity.this, "Login In SuccessFully", Toast.LENGTH_SHORT).show();
Intent i = new Intent(LoginActivity.this,AfterLoginActivity.class);

} else if (lm.getStatus().equals("0")) // login failure
Toast.makeText(LoginActivity.this, "Invalid UserName/Password ", Toast.LENGTH_SHORT).show();

public void onFailure(Throwable t) {
// String merror = error.getMessage();
Toast.makeText(LoginActivity.this, "try again", Toast.LENGTH_LONG).show(); }

Am getting null point exception at line => lm.getstatus().equals(1);
It was working fine before with retrofit 1.9 then I changed it into Retrofit 2 and am getting null point exception now!

Anu Anu
Answer has clarifications on on the new URL declaration pattern in Retrofit 2.0. It suggests

- Base URL: always ends with /
- @Url: DO NOT start with /

In your case the url might be interpreted as "". Try using

String url = "";