0

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

JohnR
  • 27
  • 7

2 Answers2

0

Did you add AppController to the AndroidManifest.xml? If not then add

<application
    android:name=".AppController"
    android:allowBackup="true"
    android:icon="@mipmap/ic_laucher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_laucher_circle"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
khushbu vadi
  • 391
  • 2
  • 10
0

Solved the problem.

Moved the public void addRemove(Integer pos, List listItems) {} to the ListItemAdapter class where I was calling it instead of Calling it from MainActivity class

JohnR
  • 27
  • 7