Skip to content
Advertisement

How to put JSON api data to recyclerview using Volley library in java?

I am trying to put JSON api data to recyclerview using volley library. My Api url=here

But it gives this error,my logcat :-

JavaScript

My Activity(test)

JavaScript

My Adapter(MainAdapter)

JavaScript

MainData class

JavaScript

I dont know what is wrong in my whether it is in test(activity), or adapter, or Maindata class. Please help, Thank you in advance.

Advertisement

Answer

The issue you are seeing originates from the fact that you are first creating an Adapter to your recycler view without initializing ArrayList<MainData> dataArrayList.

You are making a network request, which takes time, and once you create an adapter to your recycler view, in the background, it is trying to set data to itself using what you provided.

If you initialize your dataArrayList to be an empty array list, the exception you are seeing will disappear.

JavaScript

You could also opt to create and set your adapter only after your parse the response from your network request.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement