Here is my dialog code
public void registrationSuccess(final Context context, String warning, String message) {
alert = new AlertDialog.Builder(context);
alert.setTitle(warning);
alert.setMessage(message)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent i = new Intent(context, loginActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);
}
});
AlertDialog alertDialog = alert.create();
alert.show();
}
and I want to use it inside my onResponse method below
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
System.out.println("Failure!!");
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if(response.isSuccessful()) {
registrationSuccess(getApplicationContext(), getResources().getString(R.string.congrats), getResources().getString(R.string.successfull_registration));
} else {
System.out.println("FAILED");
}
}
});
getApplicationContext breaks the app with the following error showing in the console
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
With what should I replace context
?
NOTE: its non-activity class