So I have an AsyncTask class to handle populating my `RecyclerView`. It works well but when it needs to be refreshed then it crashes with a `NullPointerException`. I kind of know why but then I can't do it because I am creating a new `object` and adding it to my `list`.

This is my code:

```
  @Override
        protected void onPostExecute(String s) {
            try {
                userslist.clear();
                JSONArray jsonArray = new JSONArray(s);
                for(int i=0; i < jsonArray.length(); i++){
                    ...
                    UsersData usersData = new UsersData(var1, var2);
                    userslist.add(UsersData);
                }
                cAdapter.notifyDataSetChanged(); // Culprit line, despite the list being deleted and added again in the try block
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

```

I suspect is it something to do with the `userslist`.

This is my error logs:

```
java.lang.NullPointerException
            at lukazs.newapp.UserInfo$GetUserList.onPostExecute(UserInfo.java:218)
            at android.os.AsyncTask.finish(AsyncTask.java:741)
            at android.os.AsyncTask.access$600(AsyncTask.java:197)
            at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:654)
            at android.os.Handler.dispatchMessage(Handler.java:100)

```

EDIT: This is the method call where I populate the `recyclerview`:

```
public void populate(){
    GetUserList getUserList = new GetUserList();
    getUserList.execute();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    ...
    populate();
    }

```

This is where `cAdapter` is initialised, in `onCreate` method:

```
RecyclerView.Adapter cAdapter;
ArrayList<UserDetailsProvider> userslist = new ArrayList<UserDetailsProvider>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    populateRecyclerList();
    recyclerView = (RecyclerView) findViewById(R.id.recycleMusic);
    cAdapter = new UserDefinedAdapter(userslist);
    recyclerView.setAdapter(cAdapter);
}

```