致命异常:检测到java.lang.IndexOutOfBoundsException不一致。无效的物料位置5(偏移量:5)。状态:24
这种撞车的情况太多了!!!
我在布料上弄到的。
DateList是涉及RecyclerView片段:
public class DateList extends Fragment {
DatesItemAdapter adapter;
List<DateItem2> keyList;
CardView cardView;
double v = 1;
float radius = 1;
ProgressBarCircular mCircular;
SwipeRefreshLayout swipeRefreshLayout;
RecyclerView mRecyclerView;
Animation animSlideUp;
Animation animSlideDown;
Uri.Builder builder;
JsonObjectRequest callToServerRequest;
public DateList() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
swipeRefreshLayout.post(new Runnable() {
@Override
public void run() {
callToServer(false);
}
}
);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_date_list, container, false);
((MainActivity) getActivity()).setTitle(getString(R.string.third_page));
((MainActivity) getActivity()).setToolbarVisibility(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
container.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
mCircular = (ProgressBarCircular) view.findViewById(R.id.date_list_progressBar);
animSlideUp = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_up);
animSlideDown = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_down);
swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.date_list_swipe_refresh_layout);
mRecyclerView = (RecyclerView) view.findViewById(R.id.date_list_container);
keyList = new ArrayList<>();
adapter = new DatesItemAdapter(keyList, new DatesItemAdapter.DateItemClickListener() {
@Override
public void onClick(View v, int pos) {
if (pos < keyList.size()) {
try {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
linearLayoutManager.scrollToPositionWithOffset(pos, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, getActivity(), view);
((MainActivity) getActivity()).setTitle("Hello " + getActivity().getResources().getString(R.string.date_list_be) + " " + "World");
builder = new Uri.Builder();
builder.scheme("https")
.authority("mydomain.ir")
.appendPath("mywebservices")
.appendPath("myWs");
cardView = new CardView(getActivity());
try {
cardView.setRadius(2);
} catch (Exception e) {
e.printStackTrace();
}
cardView.findViewById(R.id.date_list_item_card_view);
radius = cardView.getRadius();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
try {
v = ((cardView.getMaxCardElevation()) * 1.5) + ((1 - Math.cos(45)) * (radius));
} catch (Exception e) {
e.printStackTrace();
}
}
try {
mRecyclerView.addItemDecoration(new DividerItemDecoration(8, getActivity(), v));
} catch (Exception e) {
e.printStackTrace();
}
try {
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
} catch (Exception e) {
e.printStackTrace();
}
mRecyclerView.setItemAnimator(new TchAnimator());
mRecyclerView.setAdapter(adapter);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mRecyclerView.setVisibility(View.GONE);
callToServer(false);
}
});
final ImageView imageView = (ImageView) view.findViewById(R.id.date_list_header_image);
final String url = "https://pic.mydomain.ir/pics/" + getResources().getString(R.string.url) + "photo.jpg";
ImageLoader loader = AppController.getInstance().getImageLoader();
loader.get(url
, new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer imageContainer, boolean b) {
try {
imageView.setImageBitmap(imageContainer.getBitmap());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
return view;
}
public void callToServer(final boolean rTime) {
String url = builder.toString();
if (rTime) {
url = url + "&rTime=1";
} else {
url = url + "&rTime=0";
}
callToServerRequest = new JsonObjectRequest(Request.Method.GET
, url
, null
, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray array = new JSONArray(response.getString("Ticks"));
// Clears list to replace new list items
keyList.clear();
adapter.notifyDataSetChanged();
for (int i = 0; i < array.length(); i++) {
JSONObject obj = new JSONObject(array.get(i).toString());
DateItem2 item = new DateItem2();
item.setAvailable(obj.getString("available"));
item.setType(obj.getString("type"));
item.setUrl(obj.getString("url"));
item.setTime(obj.getString("time"));
item.setDescription(obj.getString("description"));
keyList.add(item);
}
if (rTime) {
mCircular.setVisibility(View.GONE);
}
adapter.notifyDataSetChanged();
mRecyclerView.setVisibility(View.VISIBLE);
swipeRefreshLayout.setRefreshing(false);
} catch (JSONException e) {
e.printStackTrace();
}
if (!rTime) {
callToServer(true);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
if (rTime) {
mCircular.setVisibility(View.GONE);
}
try {
if (ConnectionDetector.IS_CONNECTED(getActivity())) {
if (volleyError.toString().contains("[]") && !rTime) {
callToServer(true);
}
}
} catch (Exception e) {
e.printStackTrace();
}
swipeRefreshLayout.setRefreshing(false);
}
});
AppController.getInstance().addToRequestQueue(callToServerRequest, "DateList" + "callToServerRequest");
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
try {
if (getView() != null) {
getView().setFocusableInTouchMode(true);
getView().requestFocus();
}
} catch (Exception e) {
e.printStackTrace();
}
getView().setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
try {
callToServerRequest.cancel();
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
});
}
}
callToServer(带有假输入)首先清除键列表,然后填充它。几毫秒后,将调用callToServer(具有true输入)来再次清除keyList,并填充新项。这两个事件将在每次刷新中重复。
这是适配器:
public class DatesItemAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<DateItem2> items;
private Context mContext;
private DateItemClickListener listener;
private Animation animRotate;
private LogAndReg logAndReg;
private View mainView;
public DatesItemAdapter(List<DateItem2> items, DateItemClickListener listener, Context mContext, View v) {
this.items = items;
this.listener = listener;
this.mContext = mContext;
animRotate = AnimationUtils.loadAnimation(mContext, R.anim.rotation);
this.mainView = v;
}
public interface DateItemClickListener {
void onClick(View v, int pos);
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
try {
View view = LayoutInflater.from(mContext).inflate(R.layout.date_list_list_item, parent, false);
switch (viewType) {
case 0:
return new GuarantyOpen(view);
case 1:
return new GuarantyClose(view);
case 2:
return new FreeOpenRefresh(view);
case 3:
return new FreeCloseRefresh(view);
case 4:
return new FreeOpen(view);
case 5:
return new FreeClose(view);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
if (holder instanceof GuarantyOpen) {
final GuarantyOpen h0 = (GuarantyOpen) holder;
h0.time.setText(items.get(h0.getAdapterPosition()).getTime());
h0.type.setText(getModelType(h0.getAdapterPosition()));
if (items.get(h0.getAdapterPosition()).getAvailable().contentEquals("500")) {
h0.available.setText(R.string.is_available);
} else {
h0.available.setText(items.get(h0.getAdapterPosition()).getAvailable());
}
if (items.get(h0.getAdapterPosition()).getDescription().contentEquals("")) {
h0.description.setVisibility(View.GONE);
} else {
h0.description.setText(items.get(h0.getAdapterPosition()).getDescription());
}
h0.url.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
h0.url.setEnabled(true);
Intent intent = new Intent(mContext, Reserve.class);
intent.putExtra("type", items.get(h0.getAdapterPosition()).getType());
intent.putExtra("time", items.get(h0.getAdapterPosition()).getTime());
mContext.startActivity(intent);
}
});
h0.url.setBackgroundResource(R.drawable.button_bg_green_selector);
} else if (holder instanceof GuarantyClose) {
final GuarantyClose h1 = (GuarantyClose) holder;
try {
h1.time.setText(items.get(h1.getAdapterPosition()).getTime());
} catch (Exception e) {
e.printStackTrace();
}
if (items.get(h1.getAdapterPosition()).getAvailable().contentEquals("500")) {
h1.available.setText(R.string.is_available);
} else {
h1.available.setText(items.get(h1.getAdapterPosition()).getAvailable());
}
} else if (holder instanceof FreeOpenRefresh) {
final FreeOpenRefresh h2 = (FreeOpenRefresh) holder;
h2.time.setText(items.get(h2.getAdapterPosition()).getTime());
h2.type.setText(getModelType(h2.getAdapterPosition()));
if (items.get(h2.getAdapterPosition()).getAvailable().contentEquals("500")) {
h2.available.setText(R.string.is_available);
} else {
h2.available.setText(items.get(h2.getAdapterPosition()).getAvailable());
}
if (!((MainActivity) mContext).isLoggedIn()) {
h2.url.setText(R.string.date_adapter_login);
} else {
h2.url.setText(R.string.date_adapter_trans);
}
if (items.get(h2.getAdapterPosition()).getDescription().contentEquals("")) {
h2.description.setVisibility(View.GONE);
} else {
h2.description.setText(items.get(h2.getAdapterPosition()).getDescription());
}
h2.url.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
h2.url.setEnabled(false);
if (!((MainActivity) mContext).isLoggedIn()) {
h2.url.setEnabled(false);
logAndReg = LogAndReg.newInstance();
logAndReg.show(((MainActivity) mContext).getSupportFragmentManager(), "tag");
h2.childLayout.setVisibility(View.GONE);
} else {
h2.url.setEnabled(true);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://" + items.get(h2.getAdapterPosition()).getUrl()));
mContext.startActivity(i);
}
}
});
} else if (holder instanceof FreeCloseRefresh) {
final FreeCloseRefresh h3 = (FreeCloseRefresh) holder;
h3.time.setText(items.get(h3.getAdapterPosition()).getTime());
if (items.get(h3.getAdapterPosition()).getAvailable().contentEquals("500")) {
h3.available.setText(R.string.is_available);
} else {
h3.available.setText(items.get(h3.getAdapterPosition()).getAvailable());
}
if (!((MainActivity) mContext).isLoggedIn()) {
h3.url.setText(R.string.date_adapter_login);
} else {
h3.url.setText(R.string.date_adapter_trans);
}
} else if (holder instanceof FreeOpen) {
final FreeOpen h4 = (FreeOpen) holder;
h4.time.setText(items.get(h4.getAdapterPosition()).getTime());
h4.available.setText(items.get(h4.getAdapterPosition()).getAvailable());
h4.type.setText(getModelType(h4.getAdapterPosition()));
if (items.get(h4.getAdapterPosition()).getAvailable().contentEquals("500")) {
h4.available.setText(R.string.is_available);
} else {
h4.available.setText(items.get(h4.getAdapterPosition()).getAvailable());
}
if (!((MainActivity) mContext).isLoggedIn()) {
h4.url.setText(R.string.date_adapter_login);
} else {
h4.url.setText(R.string.date_adapter_trans);
}
if (items.get(h4.getAdapterPosition()).getDescription().contentEquals("")) {
h4.description.setVisibility(View.GONE);
} else {
h4.description.setText(items.get(h4.getAdapterPosition()).getDescription());
}
h4.url.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
h4.url.setEnabled(false);
if (!((MainActivity) mContext).isLoggedIn()) {
h4.url.setEnabled(false);
logAndReg = LogAndReg.newInstance();
logAndReg.show(((MainActivity) mContext).getSupportFragmentManager(), "tag");
h4.childLayout.setVisibility(View.GONE);
} else {
h4.url.setEnabled(true);
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://" + items.get(h4.getAdapterPosition()).getUrl()));
mContext.startActivity(i);
}
}
});
} else if (holder instanceof FreeClose) {
final FreeClose h5 = (FreeClose) holder;
h5.time.setText(items.get(h5.getAdapterPosition()).getTime());
if (items.get(h5.getAdapterPosition()).getAvailable().contentEquals("500")) {
h5.available.setText(R.string.is_available);
} else {
h5.available.setText(items.get(h5.getAdapterPosition()).getAvailable());
}
if (!((MainActivity) mContext).isLoggedIn()) {
h5.url.setText(R.string.date_adapter_login);
} else {
h5.url.setText(R.string.date_adapter_trans);
}
}
}
@Override
public int getItemCount() {
return items.size();
}
@Override
public int getItemViewType(int position) {
return items.get(position).getexpandState().getValue();
}
private class GuarantyOpen extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView time, available, description, type;
Button url;
LinearLayout parentLayout;
GuarantyOpen(View v) {
super(v);
time = (TextView) v.findViewById(R.id.date_list_item_text_time);
available = (TextView) v.findViewById(R.id.date_list_item_text_available);
description = (TextView) v.findViewById(R.id.date_list_item_text_type);
type = (TextView) v.findViewById(R.id.date_list_item_ticket_type);
url = (Button) v.findViewById(R.id.date_list_item_btn_open_url);
url.setText(R.string.xml_reserve_reservation_btn);
parentLayout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
try {
listener.onClick(view, getAdapterPosition());
items.get(getAdapterPosition()).setexpandState(DateItemStatus.GUARANTY_CLOSE);
onBindViewHolder(this, getAdapterPosition());
} catch (Exception e) {
e.printStackTrace();
}
}
}
private class GuarantyClose extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView time;
TextView available;
Button url;
LinearLayout parentLayout;
RelativeLayout childLayout;
GuarantyClose(View v) {
super(v);
time = (TextView) v.findViewById(R.id.date_list_item_text_time);
available = (TextView) v.findViewById(R.id.date_list_item_text_available);
url = (Button) v.findViewById(R.id.date_list_item_btn_open_url);
parentLayout = (LinearLayout) v.findViewById(R.id.date_list_item_parent_layout);
childLayout = (RelativeLayout) v.findViewById(R.id.date_list_item_child_layout);
childLayout.setVisibility(View.GONE);
parentLayout.setBackgroundColor(Color.parseColor("#f3faf4"));
childLayout.setBackgroundColor(Color.parseColor("#c8e6c9"));
parentLayout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
try {
listener.onClick(view, getAdapterPosition());
items.get(getAdapterPosition()).setexpandState(DateItemStatus.GUARANTY_OPEN);
onBindViewHolder(this, getAdapterPosition());
} catch (Exception e) {
e.printStackTrace();
}
}
}
private class FreeOpenRefresh extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView time;
TextView available;
TextView description;
TextView type;
Button url;
LinearLayout parentLayout;
RelativeLayout childLayout;
FreeOpenRefresh(View v) {
super(v);
time = (TextView) v.findViewById(R.id.date_list_item_text_time);
available = (TextView) v.findViewById(R.id.date_list_item_text_available);
description = (TextView) v.findViewById(R.id.date_list_item_text_type);
type = (TextView) v.findViewById(R.id.date_list_item_ticket_type);
url = (Button) v.findViewById(R.id.date_list_item_btn_open_url);
parentLayout = (LinearLayout) v.findViewById(R.id.date_list_item_parent_layout);
childLayout = (RelativeLayout) v.findViewById(R.id.date_list_item_child_layout);
parentLayout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.date_list_item_btn_refresh) {
try {
items.get(getAdapterPosition()).setexpandState(DateItemStatus.FREE_REFRESH_OPEN);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
listener.onClick(view, getAdapterPosition());
items.get(getAdapterPosition()).setexpandState(DateItemStatus.FREE_REFRESH_CLOSE);
onBindViewHolder(this, getAdapterPosition());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
private class FreeCloseRefresh extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView time;
TextView available;
Button url;
LinearLayout parentLayout;
RelativeLayout childLayout;
FreeCloseRefresh(View v) {
super(v);
time = (TextView) v.findViewById(R.id.date_list_item_text_time);
available = (TextView) v.findViewById(R.id.date_list_item_text_available);
url = (Button) v.findViewById(R.id.date_list_item_btn_open_url);
parentLayout = (LinearLayout) v.findViewById(R.id.date_list_item_parent_layout);
childLayout = (RelativeLayout) v.findViewById(R.id.date_list_item_child_layout);
childLayout.setVisibility(View.GONE);
parentLayout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.date_list_item_btn_refresh) {
try {
items.get(getAdapterPosition()).setexpandState(DateItemStatus.FREE_REFRESH_CLOSE);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
listener.onClick(view, getAdapterPosition());
items.get(getAdapterPosition()).setexpandState(DateItemStatus.FREE_REFRESH_OPEN);
onBindViewHolder(this, getAdapterPosition());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
private class FreeOpen extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView time;
TextView available;
TextView description;
TextView type;
Button url;
LinearLayout parentLayout;
RelativeLayout childLayout;
FreeOpen(View v) {
super(v);
time = (TextView) v.findViewById(R.id.date_list_item_text_time);
available = (TextView) v.findViewById(R.id.date_list_item_text_available);
description = (TextView) v.findViewById(R.id.date_list_item_text_type);
type = (TextView) v.findViewById(R.id.date_list_item_ticket_type);
url = (Button) v.findViewById(R.id.date_list_item_btn_open_url);
parentLayout = (LinearLayout) v.findViewById(R.id.date_list_item_parent_layout);
childLayout = (RelativeLayout) v.findViewById(R.id.date_list_item_child_layout);
parentLayout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
try {
listener.onClick(view, getAdapterPosition());
items.get(getAdapterPosition()).setexpandState(DateItemStatus.FREE_CLOSER);
onBindViewHolder(this, getAdapterPosition());
} catch (Exception e) {
e.printStackTrace();
}
}
}
private class FreeClose extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView time;
TextView available;
Button url;
LinearLayout parentLayout;
RelativeLayout childLayout;
FreeClose(View v) {
super(v);
time = (TextView) v.findViewById(R.id.date_list_item_text_time);
available = (TextView) v.findViewById(R.id.date_list_item_text_available);
url = (Button) v.findViewById(R.id.date_list_item_btn_open_url);
parentLayout = (LinearLayout) v.findViewById(R.id.date_list_item_parent_layout);
childLayout = (RelativeLayout) v.findViewById(R.id.date_list_item_child_layout);
childLayout.setVisibility(View.GONE);
parentLayout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
try {
listener.onClick(view, getAdapterPosition());
items.get(getAdapterPosition()).setexpandState(DateItemStatus.FREE_OPEN);
onBindViewHolder(this, getAdapterPosition());
} catch (Exception e) {
e.printStackTrace();
}
}
}
private String getModelType(int position) {
String tType;
String type = items.get(position).getType();
switch (type) {
case "bclass":
...
break;
case "normal":
...
break;
case "phone":
...
break;
case "phone-bclass":
...
break;
}
return tType;
}
}
我根本找不出问题出在哪里!!!
这很可能是一个并发问题。我不知道JsonObjectRequest是如何工作的,但它的回调很可能是在后台线程中调用的。因此,当您在更新数据时滚动时,回收器视图将尝试创建其信息不再存在的视图。
为了避免这种情况,一个可能的解决方案是将回调例程包装在一个Runnable中,由主线程中的处理程序调用。类似这样的事情:
public void callToServer(final boolean rTime) {
String url = builder.toString();
if (rTime) {
url = url + "&rTime=1";
} else {
url = url + "&rTime=0";
}
final Handler handler = new Handler(getMainLooper());
callToServerRequest = new JsonObjectRequest(Request.Method.GET
, url
, null
, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
handler.post(new Runnable() {
@Override
public void run() {
try {
JSONArray array = new JSONArray(response.getString("Ticks"));
// Clears list to replace new list items
keyList.clear();
adapter.notifyDataSetChanged();
for (int i = 0; i < array.length(); i++) {
JSONObject obj = new JSONObject(array.get(i).toString());
DateItem2 item = new DateItem2();
item.setAvailable(obj.getString("available"));
item.setType(obj.getString("type"));
item.setUrl(obj.getString("url"));
item.setTime(obj.getString("time"));
item.setDescription(obj.getString("description"));
keyList.add(item);
}
if (rTime) {
mCircular.setVisibility(View.GONE);
}
adapter.notifyDataSetChanged();
mRecyclerView.setVisibility(View.VISIBLE);
swipeRefreshLayout.setRefreshing(false);
} catch (JSONException e) {
e.printStackTrace();
}
if (!rTime) {
callToServer(true);
}
}
});
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
handler.post(new Runnable() {
@Override
public void run() {
if (rTime) {
mCircular.setVisibility(View.GONE);
}
try {
if (ConnectionDetector.IS_CONNECTED(getActivity())) {
if (volleyError.toString().contains("[]") && !rTime) {
callToServer(true);
}
}
} catch (Exception e) {
e.printStackTrace();
}
swipeRefreshLayout.setRefreshing(false);
}
});
}
});
AppController.getInstance().addToRequestQueue(callToServerRequest, "DateList" + "callToServerRequest");
}
PS:清除列表后不需要调用notifyDataSetChanged。就在你填充它之后。
我们的QA检测到了一个bug:当旋转Android设备(Droid Turbo)时,发生了以下与RecyclerView相关的崩溃: java.lang.IndexOutOfBoundsException:检测到不一致。无效的物料位置%2(偏移量:%2)。状态:%3 对我来说,这看起来像是RecyclerView内部的一个内部错误,因为我想不出这是由我们的代码直接导致的任何方式... 有人遇到过这
我们的 QA 检测到一个错误:发生了以下与 RecyclerView 相关的崩溃:' Java . lang . indexoutofboundsexception:检测到不一致。无效的项目位置2(偏移量:2)。状态:3 一个残酷的解决方法可能是在异常发生时捕获它,并从头开始重新创建RecycleverView实例,以避免处于损坏状态。 但是,如果可能的话,我想更好地理解这个问题(也许从根源上修复
你们能帮我做这个吗 这是我添加片段的代码 但当我从添加的片段中按back时,我出现了这个错误,我的应用程序崩溃了。 为什么会这样?请帮忙。我正在使用两个片段。产品列表fragent和产品详细信息片段
我在我的应用程序中使用带有的。因为我已经从加载了,并且在后台调用服务之后,尝试通过
我的应用程序中有回收器视图。UI类似于Google Play Store应用程序。它有两个视图寻呼机和项目的列表和网格以交替的方式。所有数据都是从web服务中提取的,并在两个API调用中被分叉。列表和网格的数据是从另一个API填充的。问题是,当我快速滚动recyclerview时,我会遇到这种崩溃。滚动recyclerview时,用于在列表/网格中加载数据的API调用来自。阅读了许多关于这个主题的
我已经开始在Crashlytics上报道这次坠机事件。我不知道如何复制它,但它似乎都是内部的代码。我认为这来自于我的<代码>回收视图</代码>它从未真正改变过。用户可以刷新它,但随后会替换所有项,并调用。