简体   繁体   English

通过用户数组列表从 firebase 检索数据问题

[英]Data retrieving problem from firebase by arraylist of users

I have a firebse database shown below.我有一个如下所示的 firebse 数据库。

这是数据库

And i am trying to Get all users details by a object of User class in a arraylist of Users class shown below.我正在尝试通过下面显示的用户类数组列表中的用户类对象获取所有用户详细信息。 So that i can access later every information of users from arraylist of users.这样我以后就可以从用户数组列表中访问用户的每个信息。 I am trying to iterate a for loop to iterate over every users and get them with details.我正在尝试迭代 for 循环来迭代每个用户并获取他们的详细信息。 If i use one single User class and try to only one users details it's working but in case of arraylist it fails to initialize the array.如果我使用一个 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) {

            }
        });

And my User class is below我的用户类在下面

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;
    } }

But it's not working.但它不起作用。 Debugging apps shows arraylist size 0.调试应用程序显示数组列表大小为 0。

Debugging messages shown below.调试消息如下所示。

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

If there is something more to know please notify.如果还有什么想知道的请通知。 Here is the class where i am trying to access the arraylist of users.这是我试图访问用户数组列表的类。

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;
    }
}

Some firebase servers are down for particular ISP and even my Realtime database is not reachable while using Vodafone network, You should check if you believe that there is no error from your side.某些特定 ISP 的 Firebase 服务器已关闭,甚至在使用 Vodafone 网络时也无法访问我的实时数据库,您应该检查您是否认为您这边没有错误。 https://status.firebase.google.com/incident/Realtime%20Database/20008 https://status.firebase.google.com/incident/Realtime%20Database/20008

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM