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();
}
}
Asked
Active
Viewed 604 times
-2

AskNilesh
- 67,701
- 16
- 123
- 163

naimuddinalam
- 3
- 2
-
paste your logcat please – Milad Yarmohammadi Sep 13 '18 at 11:36
-
Would be useful to know of what class type 'response' is as well. Throw us a crumb. – Sep 13 '18 at 11:38
-
2probably ... `response.body().getSuccess()` returns null. – SRB Bans Sep 13 '18 at 11:41
-
1Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – ADM Sep 13 '18 at 11:52
3 Answers
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
-
Doesn't quite match error in title and the OP code is already guarded by isSuccessful. – Sep 13 '18 at 11:45
-
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();
}