Anonymous new Response.Listener<String>() can be replaced with lambda [duplicate]

  android, android-volley, anonymous, java, listener
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    StringRequest request = new StringRequest(url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("VOLLEY", error.toString());
        }
    });
    mQueue.add(request);
}

I have this problem, new Response.Listener() and new Response.ErrorListener() are Anonymous and when i try to run my full project, i have the error:

Attempt to invoke virtual method ‘com.android.volley.Request com.android.volley.RequestQueue.add(com.android.volley.Request)’ on a null object reference

Can anyone help me?

Source: Android Questions

LEAVE A COMMENT