Debugger:
java.lang.NullPointerException: Attempt to invoke virtual method 'com.android.volley.Request com.android.volley.RequestQueue.add(com.android.volley.Request)' on a null object reference
at .MainActivity.addRemove(MainActivity.java:234)
at .ListItemAdapter$2.onClick(ListItemAdapter.java:66)
Where is the problem?
public void addRemove(Integer pos, List<ListItem> listItems) {
if (pos!=null){
boolean isSelected=listItems.get(pos).getIsSelected();
final String spotId=listItems.get(pos).getId();
if (isSelected==true){
URL_D=URL_DATA+"api-spot-favorites-add";
}
else{
URL_D=URL_DATA+"api-spot-favorites-remove";
}
StringRequest addRequest = new StringRequest(Request.Method.POST, URL_D,
........
};
requestQueue.add(addRequest);
}
Also the addRemove(pos, listItems) is called in ListItemAdapter class and it's written in MainActivity class