My class extends AppCompatActivity
This is my class
public class Login extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        final Button loginBtn = (Button) findViewById(R.id.login_btn);
        loginBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
                Login login = new Login();
                try {
                    login.getAccessCode();
                }
                catch (IOException e){
                    Log.e("LOGIN", "I got an error", e);
                }
            }
        });
    }
    public void getAccessCode() throws IOException {
        RequestParams params = new RequestParams();
        params.put("a", "a");
        QuidoRestClient.post("/login/generateCode", params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                // If the response is JSONObject instead of expected JSONArray
                Log.d("LOGIN",response.toString());
                String code = "";
                try {
                    code = response.getString("code");
                }
                catch (JSONException e){
                }
                Context context = getApplicationContext();
                CharSequence text = "Hello toast!";
                int duration = Toast.LENGTH_SHORT;
                Toast toast = Toast.makeText(context, text, duration);
                toast.show();
            }
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray data) {
                // If the response is JSONArray instead of expected JSONObject
            }
        });
    }
}
This is the error
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.content.Context.getApplicationContext()' on a null object reference
I've also tried
Toast toast = Toast.makeText(Login.this, text, duration);
I've solved the issue by calling my method directly instead of Login login = new Login();
 
    