2017-02-18 91 views
1

我有一個recyclerview的活動,當我點擊其中的一個項目時,它會通過另一個回收站視圖導致此活動。但它不斷給我一個「E/RecyclerView:沒有適配器連接;跳過佈局」錯誤。無法解決E/RecyclerView:沒有附加適配器;跳過佈局錯誤

這裏是onCreate()方法:

@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(); 


} 

我看到類似這樣的另一個問題是說運行的其他線程之前來連接適配器,但我不相信我有這個運行任何其他線程活動。 getBundleData()只執行以下操作:

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"); 

    } 

回答

1

在logcat中,通常可以看到以下錯誤。

「E/RecyclerView:無適配器連接;跳過佈局」

不要

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

rv.setAdapter(adapter); 
rv.setLayoutManager(layoutManager); 
rv.setHasFixedSize(true); // optional