Firestore数据在Recycler View Android中



Iam正在将Firestore数据检索到javaandroid中的recycler视图。我的数据看起来像是首先有一个名称集合";用户";它有一些具有唯一id的文档,所有文档都包含名称、等级和图像,但在检索这些数据时,我在回收器视图中看不到任何内容

型号类别


public class UserModel {
String name, grade ,image;
public UserModel() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public UserModel(String name, String grade, String image) {
this.name = name;
this.grade = grade;
this.image = image;
}

适配器类


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.programiner.studyvillaadmin.R;
public class UserAdapter extends FirestoreRecyclerAdapter<UserModel, UserAdapter.ViewHolder> {
public UserAdapter(@NonNull FirestoreRecyclerOptions<UserModel> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull UserModel model) {
holder.username.setText(model.getName());
holder.usergrade.setText(model.getGrade());
Glide.with(holder.itemView.getContext()).load(model.getImage()).into(holder.profile_img);
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_row, parent, false);
return new ViewHolder(view);
}

public class ViewHolder extends RecyclerView.ViewHolder {
ImageView profile_img;
TextView username, usergrade;
public ViewHolder(@NonNull View itemView) {
super(itemView);
profile_img = itemView.findViewById(R.id.imageView2);
username = itemView.findViewById(R.id.textView12);
usergrade = itemView.findViewById(R.id.textView13);
}
}

活动代码


public class User extends AppCompatActivity {
ActivityUserBinding binding;
UserAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityUserBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
initrecyclerview();

}
private void initrecyclerview() {

Query query = FirebaseFirestore.getInstance()
.collection("Users");
FirestoreRecyclerOptions<UserModel> options = new FirestoreRecyclerOptions.Builder<UserModel>()
.setQuery(query, UserModel.class)
.build();

binding.rvUser.setLayoutManager(new LinearLayoutManager(this));
adapter = new UserAdapter(options);
binding.rvUser.setAdapter(adapter);
}

LogCat错误

2021-11-25 13:44:09.157 3751-3751/? E/YouTube: flushBinderConnectionCallbacks is unverified on SDK 28
2021-11-25 13:44:09.885 1883-1896/? E/memtrack: Couldn't load memtrack module
2021-11-25 13:44:10.610 2310-2310/? E/BluetoothAdapter: Bluetooth binder is null
2021-11-25 13:44:10.857 3911-3911/? E/oadcastreceive: Not starting debugger since process cannot load the jdwp agent.
2021-11-25 13:44:10.909 1840-1840/? E/netmgr: Failed to open QEMU pipe 'qemud:network': Invalid argument
2021-11-25 13:44:10.910 1840-1840/? E/netmgr: WifiForwarder unable to open QEMU pipe: Invalid argument
2021-11-25 13:44:11.462 3751-3814/? E/FirebaseInstanceId: Token retrieval failed: INVALID_SENDER
2021-11-25 13:44:11.526 2310-3941/? E/bjyh: RuntimeException while executing runnable bjyu{jhb@b76ad74} with executor MoreExecutors.directExecutor()
java.lang.NullPointerException: Attempt to get length of null array
at android.util.Base64.encode(Base64.java:494)
at android.util.Base64.encodeToString(Base64.java:456)
at com.google.android.gms.auth.proximity.RemoteDevice.a(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at jhb.b(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at bjyu.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):6)
at bjye.execute(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at bjyh.c(:com.google.android.gms@214218031@21.42.18 (100700-410302452):1)
at bjyh.b(:com.google.android.gms@214218031@21.42.18 (100700-410302452):3)
at rnh.done(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.set(FutureTask.java:234)
at java.util.concurrent.FutureTask.run(FutureTask.java:274)
at rne.c(:com.google.android.gms@214218031@21.42.18 (100700-410302452):6)
at rne.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):7)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at rrk.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at java.lang.Thread.run(Thread.java:764)
2021-11-25 13:44:11.631 3946-3946/? E/droid.apps.map: Not starting debugger since process cannot load the jdwp agent.
2021-11-25 13:44:12.316 3946-3975/? E/droid.apps.map: The String#value field is not present on Android versions >= 6.0
2021-11-25 13:44:12.506 2456-3449/? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!  (parcel size = 1056768)
2021-11-25 13:44:12.756 4001-4001/? E/d.process.medi: Not starting debugger since process cannot load the jdwp agent.
2021-11-25 13:44:12.848 4016-4016/? E/id.gms.unstabl: Not starting debugger since process cannot load the jdwp agent.
2021-11-25 13:44:13.210 2456-3878/? E/gle.android.gm: Invalid ID 0x00000000.
2021-11-25 13:44:13.308 2456-3878/? E/gle.android.gm: Invalid ID 0x00000000.
2021-11-25 13:44:13.535 1883-1896/? E/memtrack: Couldn't load memtrack module
2021-11-25 13:44:13.760 2456-3953/? E/WakeLock: DG:service ** IS FORCE-RELEASED ON TIMEOUT **
2021-11-25 13:44:14.436 2456-3874/? E/PhenotypeFlagCommitter: Retrieving snapshot for com.google.android.gms.playlog.uploader failed
java.util.concurrent.TimeoutException: Timed out waiting for Task
at aqlt.I(:com.google.android.gms@214218031@21.42.18 (100700-410302452):6)
at akob.c(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at akob.i(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at akob.f(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at com.google.android.gms.clearcut.init.ClearcutInitChimeraIntentService.e(:com.google.android.gms@214218031@21.42.18 (100700-410302452):5)
at pqt.onHandleIntent(:com.google.android.gms@214218031@21.42.18 (100700-410302452):4)
at com.google.android.chimera.IntentOperation.onHandleIntent(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at pqo.onHandleIntent(:com.google.android.gms@214218031@21.42.18 (100700-410302452):4)
at drp.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):5)
at dro.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):11)
at bfzx.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
2021-11-25 13:44:14.724 4096-4096/? E/d.process.acor: Not starting debugger since process cannot load the jdwp agent.
2021-11-25 13:44:16.327 2310-4135/? E/BluetoothAdapter: Bluetooth binder is null
2021-11-25 13:44:16.778 1751-1794/? E/storaged: getDiskStats failed with result NOT_SUPPORTED and size 0
2021-11-25 13:44:18.560 1883-1896/? E/memtrack: Couldn't load memtrack module
2021-11-25 13:44:18.826 2456-4134/? E/PhenotypeFlagCommitter: Retrieving snapshot for com.google.lighter.android#com.google.android.gms failed
java.util.concurrent.TimeoutException: Timed out waiting for Task
at aqlt.I(:com.google.android.gms@214218031@21.42.18 (100700-410302452):6)
at akob.c(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at akob.i(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at akob.f(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at awfk.apply(:com.google.android.gms@214218031@21.42.18 (100700-410302452):11)
at bjww.b(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at bjwx.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):9)
at bjye.execute(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at bjwt.q(:com.google.android.gms@214218031@21.42.18 (100700-410302452):1)
at bjwt.j(:com.google.android.gms@214218031@21.42.18 (100700-410302452):8)
at bjwt.m(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at bkag.e(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at bjzh.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):6)
at bkah.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):0)
at awfo.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at xuz.run(:com.google.android.gms@214218031@21.42.18 (100700-410302452):14)
at java.lang.Thread.run(Thread.java:764)
2021-11-25 13:44:19.711 1883-1896/? E/memtrack: Couldn't load memtrack module
2021-11-25 13:44:19.896 2999-2999/? E/Finsky: [2] CheckinReceiver.c(2): Receiver disabled.
2021-11-25 13:44:21.376 1883-1896/? E/memtrack: Couldn't load memtrack module
2021-11-25 13:44:21.972 1883-1896/? E/memtrack: Couldn't load memtrack module
2021-11-25 13:44:21.994 1883-1896/? E/memtrack: Couldn't load memtrack module
2021-11-25 13:44:22.800 2310-4135/? E/BluetoothAdapter: Bluetooth binder is null
2021-11-25 13:44:23.089 3218-3230/? E/CarrierServices: [146] iez.getFile: File not found.: /data/user/0/com.google.android.apps.messaging/files/httpft_pending (No such file or directory)
java.io.FileInputStream.open0(Native Method)
java.io.FileInputStream.open(FileInputStream.java:231)
java.io.FileInputStream.<init>(FileInputStream.java:165)
android.app.ContextImpl.openFileInput(ContextImpl.java:560)
android.content.ContextWrapper.openFileInput(ContextWrapper.java:202)
iez.getFile(SourceFile:20)
com.google.android.apps.messaging.rcsmigration.RcsStateProvider.buildRcsState(SourceFile:136)
com.google.android.apps.messaging.rcsmigration.RcsStateProvider.getRcsState(SourceFile:6)
com.google.android.ims.rcsmigration.IRcsStateProvider$Stub.dispatchTransaction(SourceFile:10)
com.google.android.aidl.BaseStub.onTransact(SourceFile:18)
android.os.Binder.execTransact(Binder.java:731)

解决方案

@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}

解决方案

请确保在适配器上调用start listening以启动与Cloud Firestore的连接,否则将不会加载任何数据。

@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}

@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}

相关内容

  • 没有找到相关文章

最新更新