-2
 if(response.isSuccessful())
               {
                   if(response.body().getSuccess().equalsIgnoreCase("1")||response.body().getSuccess().equalsIgnoreCase("2"))
                   {


                       String message = response.body().getMessage();
                       // Snackbar.make(parentView, message, Snackbar.LENGTH_SHORT).show();
                       Toast.makeText(Login.this,message,Toast.LENGTH_SHORT).show();
                       Intent i = new Intent(Login.this, DashBoard.class);
                       startActivity(i);
                       finish();
                       overridePendingTransition(R.anim.enter_from_right, R.anim.exit_out_right);
                   }
                   else if(response.body().getSuccess().equalsIgnoreCase("0"))
                   {
                       String message = response.body().getMessage();
                       // Snackbar.make(parentView, message, Snackbar.LENGTH_SHORT).show();
                       Toast.makeText(Login.this,message,Toast.LENGTH_SHORT).show();
                   }else {
                       Toast.makeText(Login.this, getString(R.string.unexpected_response), Toast.LENGTH_SHORT).show();
                   }

               }else {
                   Toast.makeText(Login.this, response.message(), Toast.LENGTH_LONG).show();
               }
           }
AskNilesh
  • 67,701
  • 16
  • 123
  • 163

3 Answers3

0

Probably response.body().getSuccess() returning null here .

change your logic as.

 if(response.isSuccessful() && response.body().getSuccess() != null)
               {
..

Edits

and as per Andy's answer

Toast.makeText(Login.this, response.message(), Toast.LENGTH_LONG).show();

also can cause exception in case of null.

SRB Bans
  • 3,096
  • 1
  • 10
  • 21
0

Change your equal condition like this, And exception will be handled automatically

 if (response.isSuccessful()) {
        if ("1".equalsIgnoreCase(response.body().getSuccess()) || "2".equalsIgnoreCase(response.body().getSuccess())) {
            //do your work
        } else if ("0".equalsIgnoreCase(response.body().getSuccess())) {
            //do your work
        }else {
            //do your work
         // Toast.makeText(Login.this, getString(R.string.unexpected_response), Toast.LENGTH_SHORT).show();
        }
    } else {
        //do your work
    }

Hope it helps you.

Pradeep Kumar
  • 586
  • 3
  • 19
0

This code executes when "not successful" which probably means you are passing a null to the toaster:

}else {
  Toast.makeText(Login.this, response.message(), Toast.LENGTH_LONG).show();
}