我有如下所示的firebse数据库。
我正在尝试通过下面显示的Users类的数组列表中的User类的对象获取所有用户的详细信息。这样我以后就可以从用户数组列表访问用户的所有信息。我试图迭代一个for循环,以遍历每个用户并为他们提供详细信息。如果我只使用一个User类,并且只尝试让一个用户详细说明它正在运行,但是如果使用arraylist,它将无法初始化该数组。
final DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference().child("users");
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){
Log.d("Members", "Fill User Array");
usersArray.add(dataSnapshot1.getValue(User.class));
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
我的User类在下面
package com.aam.mkc;
public class User {
private String username;
private String roll;
private String phone;
private String email;
private String password;
public User() {
}
public User(String username, String roll, String phone, String email, String password) {
this.username = username;
this.roll = roll;
this.phone = phone;
this.email = email;
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getRoll() {
return roll;
}
public void setRoll(String roll) {
this.roll = roll;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
} }
但是它不起作用。调试应用程序显示arraylist大小为0。
下面显示的调试消息。
dataSnapshot = {DataSnapshot@8946} "DataSnapshot { key = users, value = {SKCtzaeoNnYfB3QLNZEx0fRkrjC2={password=password, phone=01518555666, roll=47, email=tasrifajuni44@gmail.com, username=Tasrifa islam}, XiXJGeb2PuR8sNg59mF0dkY7wI83={password=password, phone=01587112255, roll=14, email=aamasudrana2020@gmail.com, username=MASUD RANA}, W9sHjQGiGZgCJL8VxiUdkf4lduw1={password=password, phone=01518600135, roll=32, email=abdullahalmasum777@gmail.com, username=ABDULLAH AL MASUM}} }"
usersArray = {ArrayList@8949} size = 0
dataSnapshot1 = {DataSnapshot@8947} "DataSnapshot { key = SKCtzaeoNnYfB3QLNZEx0fRkrjC2, value = {password=password, phone=01518555666, roll=47, email=tasrifajuni44@gmail.com, username=Tasrifa islam} }"
this = {Members$1@8945}
//Logcat
Build Date : 03/01/19
OpenGL ES Shader Compiler Version: EV031.25.03.02
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.7.5.R1.09.00.00.464.039
Remote Branch : NONE
Reconstruct Branch : NOTHING
2020-09-02 19:49:39.363 4485-4541/com.aam.mkc I/Adreno: Build Config : S L 6.0.7 AArch32
2020-09-02 19:49:39.368 4485-4541/com.aam.mkc I/Adreno: PFP: 0x005ff110, ME: 0x005ff066
2020-09-02 19:49:39.374 4485-4541/com.aam.mkc I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2020-09-02 19:49:39.374 4485-4541/com.aam.mkc I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2020-09-02 19:49:39.375 4485-4541/com.aam.mkc I/OpenGLRenderer: Initialized EGL, version 1.4
2020-09-02 19:49:39.375 4485-4541/com.aam.mkc D/OpenGLRenderer: Swap behavior 2
2020-09-02 19:49:40.356 4485-4540/com.aam.mkc I/Timeline: Timeline: Activity_launch_request time:145685894
2020-09-02 19:49:40.393 4485-4485/com.aam.mkc W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@d2fe96d
2020-09-02 19:49:40.815 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
2020-09-02 19:49:41.167 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden field Landroid/view/View;->mAccessibilityDelegate:Landroid/view/View$AccessibilityDelegate; (light greylist, reflection)
2020-09-02 19:49:41.565 4485-4485/com.aam.mkc W/Activity: Slow Operation: Activity com.aam.mkc/.MainActivity onCreate took 1083ms
2020-09-02 19:49:41.732 4485-4485/com.aam.mkc W/Activity: Slow Operation: Activity com.aam.mkc/.MainActivity onStart took 131ms
2020-09-02 19:49:42.375 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (light greylist, reflection)
2020-09-02 19:49:42.375 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist, reflection)
2020-09-02 19:49:42.375 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist, reflection)
2020-09-02 19:49:42.375 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (light greylist, reflection)
2020-09-02 19:49:42.375 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (light greylist, reflection)
2020-09-02 19:49:42.376 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection)
2020-09-02 19:49:43.512 4485-4485/com.aam.mkc I/Choreographer: Skipped 96 frames! The application may be doing too much work on its main thread.
2020-09-02 19:49:43.766 4485-4541/com.aam.mkc I/OpenGLRenderer: Davey! duration=1867ms; Flags=0, IntendedVsync=145687436834827, Vsync=145689036834763, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=145689052656610, AnimationStart=145689052982755, PerformTraversalsStart=145689053030099, DrawStart=145689091094370, SyncQueued=145689235642755, SyncStart=145689235896974, IssueDrawCommandsStart=145689236288328, SwapBuffers=145689303856557, FrameCompleted=145689305083797, DequeueBufferDuration=2009000, QueueBufferDuration=532000,
2020-09-02 19:49:43.773 4485-4485/com.aam.mkc W/Looper: Slow Looper: doFrame is 1614ms late because of 2 msg, msg 1 took 1500ms (late=1ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver), msg 2 took 213ms (late=1442ms h=android.view.ViewRootImpl$ViewRootHandler c=androidx.appcompat.app.AppCompatDelegateImpl$2)
2020-09-02 19:49:45.276 4485-4485/com.aam.mkc W/com.aam.mkc: Verification of void com.aam.mkc.Members.onViewCreated(android.view.View, android.os.Bundle) took 147.234ms
2020-09-02 19:49:45.311 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/view/View;->getTransitionAlpha()F (light greylist, linking)
2020-09-02 19:49:45.312 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/view/View;->setTransitionAlpha(F)V (light greylist, linking)
2020-09-02 19:49:45.313 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/view/View;->setAnimationMatrix(Landroid/graphics/Matrix;)V (light greylist, linking)
2020-09-02 19:49:45.313 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/view/View;->transformMatrixToGlobal(Landroid/graphics/Matrix;)V (light greylist, linking)
2020-09-02 19:49:45.313 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/view/View;->transformMatrixToLocal(Landroid/graphics/Matrix;)V (light greylist, linking)
2020-09-02 19:49:45.314 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/view/View;->setLeftTopRightBottom(IIII)V (light greylist, linking)
2020-09-02 19:49:45.314 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/view/View;->setTransitionVisibility(I)V (dark greylist, linking)
2020-09-02 19:49:45.618 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden field Landroid/view/View;->mViewFlags:I (light greylist, reflection)
2020-09-02 19:49:45.621 4485-4485/com.aam.mkc W/com.aam.mkc: Accessing hidden method Landroid/view/ViewGroup;->suppressLayout(Z)V (light greylist, linking)
2020-09-02 19:49:45.750 4485-4485/com.aam.mkc W/Looper: Slow Looper: doFrame is 353ms late because of 2 msg, msg 2 took 343ms (late=26ms h=android.view.ViewRootImpl$ViewRootHandler c=android.view.View$PerformClick)
2020-09-02 19:49:47.285 4485-4485/com.aam.mkc W/Looper: Slow Looper: doFrame is 363ms late because of 3 msg, msg 1 took 288ms (late=353ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver), msg 3 took 237ms (late=474ms h=android.os.Handler c=androidx.fragment.app.FragmentManagerImpl$2)
2020-09-02 19:49:47.287 4485-4485/com.aam.mkc I/Choreographer: Skipped 75 frames! The application may be doing too much work on its main thread.
2020-09-02 19:49:47.289 4485-4541/com.aam.mkc I/OpenGLRenderer: Davey! duration=1647ms; Flags=0, IntendedVsync=145691179814869, Vsync=145691529814855, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=145691542530932, AnimationStart=145691542851244, PerformTraversalsStart=145691553275202, DrawStart=145692737066660, SyncQueued=145692816829889, SyncStart=145692816994681, IssueDrawCommandsStart=145692817545775, SwapBuffers=145692825474681, FrameCompleted=145692827469681, DequeueBufferDuration=448000, QueueBufferDuration=1030000,
2020-09-02 19:49:47.340 4485-4541/com.aam.mkc I/OpenGLRenderer: Davey! duration=1314ms; Flags=0, IntendedVsync=145691564245589, Vsync=145692814245539, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=145692827001087, AnimationStart=145692827080775, PerformTraversalsStart=145692863948952, DrawStart=145692866082077, SyncQueued=145692874263379, SyncStart=145692874452546, IssueDrawCommandsStart=145692874733119, SwapBuffers=145692877656556, FrameCompleted=145692878947702, DequeueBufferDuration=361000, QueueBufferDuration=636000,
2020-09-02 19:49:47.340 4485-4485/com.aam.mkc W/Looper: Slow Looper: doFrame is 1261ms late because of 1 msg, msg 1 took 1275ms (late=363ms h=android.view.Choreographer$FrameHandler c=android.view.Choreographer$FrameDisplayEventReceiver)
2020-09-02 19:49:47.402 4485-4559/com.aam.mkc D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2020-09-02 19:49:52.470 4485-4485/com.aam.mkc D/Members: Fill User Array. //why only one iteration
如果还有其他事情要通知,请通知。 这是我要访问用户的数组列表的类。
package com.aam.mkc;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class MembersListViewAdapter extends BaseAdapter {
Context context;
ArrayList<User> usersArray;
public MembersListViewAdapter(Context context, ArrayList<User> usersArray) {
this.context = context;
this.usersArray = usersArray;
}
@Override
public int getCount() {
return (usersArray.size() == 0)?70:usersArray.size(); //here shows arraylist size is 0
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.members_single_listview, parent, false);
ImageView profileImg = (ImageView) convertView.findViewById(R.id.member_user_profile_img);
TextView name = (TextView) convertView.findViewById(R.id.tv_members_profile_name);
TextView roll = (TextView) convertView.findViewById(R.id.tv_members_roll);
// profileImg.setImageURI(images[position]);
// name.setText(names[position]);
// roll.setText(rolls[position]);
return convertView;
}
}
答案 0 :(得分:0)
使用特定的ISP时,某些firebase服务器已关闭,甚至在使用Vodafone网络时,我的实时数据库也无法访问,您应该检查一下您是否认为自己没有错。 https://status.firebase.google.com/incident/Realtime%20Database/20008