there is a blunder in MainRecyclerView
‘s onCreate()
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
dataList = new ArrayList<>(); // your dataList is empty here...
recyclerView.setAdapter(adapter); // your Adapter is null here. (not initialized)
RequestJsonArray();
You need to call method which prepares your dataList before passing it to Adapter.
Do call methods at proper position.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_recycler);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
dataList = new ArrayList<>();
RequestJsonArray();
adapter = new RecyclerViewListview(this, dataList);
recyclerView.setAdapter(adapter);
}
Now inside your getData()
comment out lines after dataList.add(data);
, then clean project, rebuild then run.
Now as you have edited your question: try like this in onBindViewHolder()
of RecyclerAdapter.
myHolder.song_name.setText("" + dataList.get(position).getSong_name());
myHolder.song_year.setText("" + dataList.get(position).getSong_year());
myHolder.song_year.setText("" + dataList.get(position).getSong_author());
4
solved No adapter attached; skipping layout recyclerview error