Я нашел похожие вопросы в Stackoverflow, но никто с рабочим ответом, и я не могу понять, как исправить эту проблему.FirebaseRecyclerAdapter error: java.lang.Throwable: addInArray
RecyclerView
Мой кажется, работает хорошо, но он загружает медленно, и я получаю эту ошибку повторяющейся 20 раз лишь на RecyclerView
из 4 предметов.
Мой журнал регистрации ошибок (в 20 раз эта ошибка):
D/ViewGroup: addInArray been called, this = android.support.v7.widget.RecyclerView{...} ,child = android.widget.LinearLayout{...} ,call stack = java.lang.Throwable: addInArray
at android.view.ViewGroup.addInArray(ViewGroup.java:3786)
at android.view.ViewGroup.attachViewToParent(ViewGroup.java:4353)
at android.support.v7.widget.RecyclerView.access$000(RecyclerView.java:155)
at android.support.v7.widget.RecyclerView$5.attachViewToParent(RecyclerView.java:727)
at android.support.v7.widget.ChildHelper.attachViewToParent(ChildHelper.java:239)
at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:7385)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7362)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7350)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1459)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1408)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:580)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3379)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3194)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3632)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1193)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1888)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1742)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1651)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:515)
at android.widget.FrameLayout.onLayout(FrameLayout.java:450)
at android.view.View.layout(View.java:15146)
at android.view.ViewGroup.layout(ViewGroup.java:4866)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2342)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2048)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1211)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6282)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop
Это мой код:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
LinearLayoutManager manager = new LinearLayoutManager(this);
listRaces.setHasFixedSize(true);
FirebaseRecyclerAdapter mAdapter = new FirebaseRecyclerAdapter<Race, ViewHolder>(Race.class, R.layout.races_row, ViewHolder.class, ref.child(Constant.FIREBASE_RACES).orderByChild("runners/" + User.getId()).equalTo(true).limitToFirst(4)) {
@Override
protected void populateViewHolder(ViewHolder viewHolder, Race race, int position) {
MyLog.log(String.valueOf(position));
if(position<3) {
viewHolder.setDistance(String.valueOf(race.distance) + " Km");
viewHolder.setLevels(String.valueOf(race.level_min) + " - " + String.valueOf(race.level_max));
viewHolder.setRunners(String.valueOf(race.signed_runners) + "/" + String.valueOf(race.max_runners));
viewHolder.setTime(TimeHandler.timestampToDate(String.valueOf(race.date)));
} else {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
viewHolder.textListDistance.setLayoutParams(layoutParams);
viewHolder.setDistance("Ver todas...");
viewHolder.textListDistance.setTextSize(14f);
viewHolder.textListDistance.setGravity(Gravity.CENTER);
viewHolder.textListDistance.setTypeface(null, Typeface.ITALIC);
}
}
};
listRaces.setAdapter(mAdapter);
listRaces.setLayoutManager(manager);
И это мой ViewHolder
класс:
public static class ViewHolder extends RecyclerView.ViewHolder {
private final TextView textListDistance;
private final TextView textListLevels;
private final TextView textListRunners;
private final TextView textListTime;
public ViewHolder(View itemView) {
super(itemView);
textListDistance = (TextView) itemView.findViewById(R.id.textListDistance);
textListLevels = (TextView) itemView.findViewById(R.id.textListLevels);
textListRunners = (TextView) itemView.findViewById(R.id.textListRunners);
textListTime = (TextView) itemView.findViewById(R.id.textListTime);
}
public void setDistance(String distance) {
textListDistance.setText(distance);
}
public void setLevels(String levels) {
textListLevels.setText(levels);
}
public void setRunners(String runners) {
textListRunners.setText(runners);
}
public void setTime(String time) {
textListTime.setText(time);
}
}
Я действительно будет оцените любую помощь для этого. Благодарю.
EDIT:
Даже при таком упрощенном коде ошибки остаются:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
LinearLayoutManager manager = new LinearLayoutManager(this);
listRaces.setLayoutManager(manager);
listRaces.setHasFixedSize(true);
FirebaseRecyclerAdapter mAdapter = new FirebaseRecyclerAdapter<Race, ViewHolder>(Race.class, R.layout.races_row, ViewHolder.class, ref.child(Constant.FIREBASE_RACES).orderByChild("runners/" + User.getId()).equalTo(true).limitToFirst(4)) {
@Override
protected void populateViewHolder(ViewHolder viewHolder, Race race, int position) {
viewHolder.setDistance(String.valueOf(race.distance) + " Km");
viewHolder.setLevels(String.valueOf(race.level_min) + " - " + String.valueOf(race.level_max));
viewHolder.setRunners(String.valueOf(race.signed_runners) + "/" + String.valueOf(race.max_runners));
viewHolder.setTime(TimeHandler.timestampToDate(String.valueOf(race.date)));
}
};
listRaces.setAdapter(mAdapter);
Вот мой races_row
расположение:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:background="@drawable/list_races_public"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="14dp">
<TextView
android:id="@+id/show_all"
android:visibility="gone"
android:gravity="center"
android:text="Ver todas..."
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14dp"
android:textStyle="italic" />
<TextView android:layout_width="60dp"
android:layout_height="wrap_content"
android:text="5 Km"
android:textStyle="bold"
android:textSize="18dp"
android:id="@+id/textListDistance"
android:layout_marginRight="10dp"
android:gravity="right" />
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="@+id/textListLevels"
android:text="1 - 5"
android:textAlignment="center" />
<ImageView
android:id="@+id/icon"
android:layout_width="16dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:src="@drawable/user"
android:layout_marginTop="2dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textListRunners"
android:text="3/5"
android:layout_marginLeft="10dp"
android:textSize="16dp" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textListTime"
android:text="-3:59"
android:textSize="16dp"
android:gravity="right" />
</LinearLayout>
А вот RecyclerView
вынесенном устройства:
Большое спасибо за внимание.
Никто не может помочь? –