1

I have an activity with a recyclerview, and when I click on one of the items in it, it leads to this activity with another recycler view. However it keeps giving me a "E/RecyclerView: No adapter attached; skipping layout" error.

Here is the onCreate() method:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getBundleData();
    setContentView(R.layout.activity_device_sensor_report);

    context = this;
    LiveDataInfo liveData = new LiveDataInfo(liveDataCat,liveDataNum);
    adapter = new AdapterLiveData(context, liveData);
    rv = (RecyclerView) findViewById(R.id.rv_liveData);
    layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false);
    rv.setLayoutManager(layoutManager);
    rv.setAdapter(adapter);


    //mqttSetup();
    drawGraph();


}

I saw another question similar to this that said to attach the adapter before running other threads but I don't believe I have any other threads running in this activity. getBundleData() just does the following:

Bundle extras = getIntent().getExtras();
    if (extras != null) {
        deviceID = extras.getString("DeviceID");
        temperature = extras.getParcelableArrayList("temperatureData");
        humidity = extras.getParcelableArrayList("humidityData");
        liveDataCat = extras.getParcelableArrayList("liveDataCat");
        liveDataNum = extras.getParcelableArrayList("liveDataNum");

    }
Tirth Rami
  • 271
  • 4
  • 15

1 Answers1

1

In the logcat, you can often see following error.

"E/RecyclerView: No adapter attached; skipping layout"

Don't

rv.setLayoutManager(layoutManager);
rv.setAdapter(adapter);

Do

rv.setAdapter(adapter);
rv.setLayoutManager(layoutManager);
rv.setHasFixedSize(true); // optional
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198