Data parsed correctly from server but Android recyclerview is empty

Tags: , , , ,

I made an online music player with PHP code server and I have no problem fetching data in JSON format. I have a problem with the Android side where no data is shown in my recyclerview although I initialized it correctly. Please help me to find out what’s wrong.

Here’s my code:


public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
RequestQueue requestQueue;
Context context;
ListAdapter adapter;
LinearLayoutManager layoutManager;
List<Listening> list = new ArrayList<>();
String url = "";
AccessDataOnServer data;

protected void onCreate(Bundle savedInstanceState) {
    context = this;
    recyclerView = (RecyclerView) findViewById(;
    requestQueue = Volley.newRequestQueue(context);
    layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
    adapter = new ListAdapter(list, context);
    data = new AccessDataOnServer();
    data.getData(context, list, recyclerView, url, requestQueue);


public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ViewHolder> {

List<Listening> listeningList;
Context context;

public ListAdapter(List<Listening> listeningList, Context context) {
    this.listeningList = listeningList;
    this.context = context;

public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.items, parent, false);
    return new ViewHolder(view);

public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    final Listening listening = listeningList.get(position);

public int getItemCount() {
    return listeningList.size();

public static class ViewHolder extends RecyclerView.ViewHolder {
    CardView cardView;
    ImageView avatar;
    TextView track, term;

    public ViewHolder(@NonNull View itemView) {
        cardView = itemView.findViewById(;
        avatar = itemView.findViewById(;
        track = itemView.findViewById(;
        term = itemView.findViewById(;

Class to get my data by help of Volley Library:

public class AccessDataOnServer extends AppCompatActivity {
RequestQueue req;
Context context;
ListAdapter adapter;
List<Listening> list1 = new ArrayList<>();
String url = "";

public void getData(final Context con, final List<Listening> list1, final RecyclerView recyclerView, String url, RequestQueue req
) {
    this.req = req;
    req = Volley.newRequestQueue(con);
    this.list1 = list1;
    JsonObjectRequest job = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        public void onResponse(JSONObject response) {

            try {

                JSONArray jsonArray = response.getJSONArray("music");

                for (int i = 0; i < jsonArray.length(); i++) {

                    JSONObject job = jsonArray.getJSONObject(i);

                    String title = job.getString("title");
                    String cover = job.getString("cover");
                    String link = job.getString("track");
                    String term = job.getString("term");

                    Listening m = new Listening();


                adapter = new ListAdapter(list1, con);
                recyclerView.setItemAnimator(new DefaultItemAnimator());

            } catch (Exception e) {
                Toast.makeText(con, "try error", Toast.LENGTH_SHORT).show();


    }, new Response.ErrorListener() {
        public void onErrorResponse(VolleyError error) {

            Toast.makeText(con, "not response", Toast.LENGTH_SHORT).show();



My data model:

public class Listening {

private String title;
private String term;
private String cover;
private String trackLink;

public String getTitle() {
    return title;

public void setTitle(String title) {
    this.title = title;

public String getTerm() {
    return term;

public void setTerm(String term) {
    this.term = term;

public String getCover() {
    return cover;

public void setCover(String cover) {
    this.cover = cover;

public String getTrackLink() {
    return trackLink;

public void setTrackLink(String trackLink) {
    this.trackLink = trackLink;


Your codes work correctly and there’s no problem with them. Did you test it on emulator? Try to wipe data on emulator or test on physical device. Your problem should be solved.

Source: stackoverflow