我有一个活动类,我将它转换为片段类。我在我的异步任务的onPostExecute中收到错误。
private class FetchData extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... voids) {
displayData();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
try {
Collections.sort(mData);
} catch (IllegalStateException ise) {
LOG.warn("Illegal state exception, ignoring it {}", ise);
}
PrintStockAdapter adapter = new PrintStockAdapter(getActivity().getApplicationContext(), mData);
details.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
错误发生在这里,
details.setAdapter(adapter);
日志,
java.lang.ClassCastException: android.support.v4.view.ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
at android.widget.ListView.clearRecycledState(ListView.java:538)
at android.widget.ListView.resetList(ListView.java:524)
at android.widget.ListView.setAdapter(ListView.java:468)
at com.app.forms.InventoryReportFragment$FetchData.onPostExecute(InventoryReportFragment.java:253)
at com.app.forms.InventoryReportFragment$FetchData.onPostExecute(InventoryReportFragment.java:236)
变量详细信息是列表视图。 private ListView details;
将活动迁移到片段时,我在哪里出错了?每次异步任务运行时都会发生此崩溃。