我想使用for循环检索我的Firebase数据库的所有子级,数据将在片段中显示在recyclerview中。当我去事件片段时,应用程序崩溃,错误指出了要循环的那一行 这是我的代码,
events.java (这是片段)
FirebaseDatabase.getInstance().getReference().child("Users/" + mUser.getUid() + "/Groups/RequestedGroups").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()){
value = ds.child("GroupID").getValue().toString();
groupId.add(value);
}
retrieveGroups(groupId);
}
private void retrieveGroups(ArrayList<String> groupId) {
if(groupId != null){
for(String value : groupId){
FirebaseDatabase.getInstance().getReference().child("Events/"+value).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot d : dataSnapshot.getChildren()){
Event_Retrieve e = d.getValue(Event_Retrieve.class); // error point out this line
list.add(e);
}
adapter = new MyAdapter(events.this.getActivity(),list);
recyclerView.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(events.this.getActivity(), "oops", Toast.LENGTH_SHORT).show();
}
});
}
}
}
Event_Retrieve .java
public class Event_Retrieve {
public String eventname;
public String eventdescription;
public String eventdate;
public String eventtime;
public String eventphotourl;
public String latitude;
public String lingitude;
public ArrayList<String> acceptedmember;
public ArrayList<String> invitedmember;
public Event_Retrieve(){
}
public Event_Retrieve(String eventname, String eventdescription, String eventdate, String eventtime, String eventphotourl, String latitude, String lingitude, ArrayList<String> acceptedmember, ArrayList<String> invitedmember) {
this.eventname = eventname;
this.eventdescription = eventdescription;
this.eventdate = eventdate;
this.eventtime = eventtime;
this.eventphotourl = eventphotourl;
this.latitude = latitude;
this.lingitude = lingitude;
this.acceptedmember = acceptedmember;
this.invitedmember = invitedmember;
}
public String getEventname() {
return eventname;
}
public String getEventdescription() {
return eventdescription;
}
public String getEventdate() {
return eventdate;
}
public String getEventtime() {
return eventtime;
}
public String getEventphotourl() {
return eventphotourl;
}
public String getLatitude() {
return latitude;
}
public String getLingitude() {
return lingitude;
}
public ArrayList<String> getAcceptedmember() {
return acceptedmember;
}
public ArrayList<String> getInvitedmember() {
return invitedmember;
}
}
fragment_event.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
tools:context=".places">
<!-- TODO: Update blank fragment layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/eventID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="Events"
android:textColor="#000"
android:textSize="30sp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Logcat错误
E/HotwordDetector: Error at creating and/or starting hotword recognition.
java.lang.IllegalArgumentException: Invalid speaker model provided
at com.google.speech.micro.GoogleHotwordRecognizer.nativeNew(Native Method)
at com.google.speech.micro.GoogleHotwordRecognizer.<init>(SourceFile:6)
at com.google.android.libraries.assistant.hotword.k.a(SourceFile:66)
at com.google.android.libraries.assistant.hotword.k.at(SourceFile:35)
at com.google.android.apps.gsa.voiceinteraction.hotword.a.dGU(SourceFile:48)
at com.google.android.voiceinteraction.GsaVoiceInteractionService.dGU(SourceFile:109)
at com.google.android.voiceinteraction.g.oa(SourceFile:13)
at com.google.android.libraries.assistant.hotword.f.a(SourceFile:30)
at com.google.android.libraries.assistant.hotword.g.run(Unknown Source)
at com.google.android.libraries.gsa.runner.a.b.run(Unknown Source)
at com.google.android.apps.gsa.shared.util.concurrent.b.cq.bsW(SourceFile:2)
at com.google.android.apps.gsa.shared.util.concurrent.b.cp.run(SourceFile:5)
at com.google.android.apps.gsa.shared.util.concurrent.b.i.run(Unknown Source)
at com.google.android.apps.gsa.shared.util.concurrent.b.bs.run(SourceFile:3)
at com.google.android.apps.gsa.shared.util.concurrent.b.bs.run(SourceFile:3)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:760)
at com.google.android.apps.gsa.shared.util.concurrent.b.o.run(SourceFile:6)
我的数据库结构
这是测试数据