我正在创建一个应用程序,在活动中我收到来自firebase的数据列表,如果数据引用为空则应用程序崩溃,我尝试吐司如果传入列表大小大于-1那么它意味着没有找到数据所以Toast一条消息没有结果,但它没有工作
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
view.setSelected(true);
InComingDataList.clear();
final String BG = adapterView.getItemAtPosition(i).toString();
Ref = FirebaseDatabase.getInstance().getReference().child("RequestsOrderByBlood").child(BG);
Ref.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getValue(subRequest.class) != null) {
InComingDataList.add(dataSnapshot.getValue(subRequest.class));
Collections.reverse(InComingDataList);
t.setVisibility(View.GONE);
t22.setText("Showing BloodRequests for " + BG);
adapter.notifyDataSetChanged();
RecView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int position = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
listLength.setText(Integer.toString(position + 1) + " / " + adapter.getItemCount());
}
});
} else {
Toast.makeText(viewRequest.this, "Sorry No Found", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
listLength.setVisibility(View.VISIBLE);
}
});
logcat的
ava.lang.IndexOutOfBoundsException:检测到不一致。无效 项目位置1(偏移:1).state:2 在 android.support.v7.widget.RecyclerView $ Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5546) 在 android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5482) 在 android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:5478) 在 android.support.v7.widget.LinearLayoutManager $ LayoutState.next(LinearLayoutManager.java:2215) 在 android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1542) 在 android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1502) 在 android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1316) 在 android.support.v7.widget.LinearLayoutManager.scrollHorizontallyBy(LinearLayoutManager.java:1049) 在 android.support.v7.widget.RecyclerView.scrollByInternal(RecyclerView.java:1723) 在 android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2927) 在android.view.View.dispatchTouchEvent(View.java:9998) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2828) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2499) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2514) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2514) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2514) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2514) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2514) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2514) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2839) 在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2514) 在 com.android.internal.policy.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:2816) 在 com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1848) 在android.app.Activity.dispatchTouchEvent(Activity.java:3046) 在 android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69) 在 com.android.internal.policy.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:2777) 在android.view.View.dispatchPointerEvent(View.java:10233) 在 android.view.ViewRootImpl $ ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5397) 在 android.view.ViewRootImpl $ ViewPostImeInputStage.onProcess(ViewRootImpl.java:5233) 在 android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:4673) 在 android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:4726) 在 android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:4692) 在 android.view.ViewRootImpl $ AsyncInputStage.forward(ViewRootImpl.java:4834) 在android.view.ViewRootImpl $ InputStage.apply(ViewRootImpl.java:4700) 在 android.view.ViewRootImpl $ AsyncInputStage.apply(ViewRootImpl.java:4891) 在 android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:4673) 在 android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:4726) 在 android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:4692) 在android.view.ViewRootImpl $ InputStage.apply(ViewRootImpl.java:4700) 在 android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:4673) 在android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7359) 在 android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7237) 在android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java