簡體   English   中英

為什么全局聲明TextViews不能從Firebase獲取數據

[英]Why declaring TextViews gloabally doesn't fetch data from Firebase

public void loadUserInformation() {
    DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
    final DatabaseReference usesrRef = rootRef.child("Users").child(Uid);
    final ValueEventListener eventListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            ImageView profilePic = (ImageView) findViewById(R.id.imageView);
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                String name = postSnapshot.child("Name").getValue().toString();
                String status = postSnapshot.child("Status").getValue().toString();
                String image = dataSnapshot.child("Image").getValue().toString();

                Name.setText(name);
                Status.setText(status);

                Name.setVisibility(View.VISIBLE);
                Status.setVisibility(View.VISIBLE);

                Picasso.get().load(image).into(profilePic);

            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Toast.makeText(getApplicationContext(), "Error Loading UserDetails", Toast.LENGTH_LONG).show();
        }
    };
    usesrRef.addListenerForSingleValueEvent(eventListener);
}

它在行上返回空指針異常...字符串名稱= postsnapshot:dataSnapshot.getChildren())

我知道如果我在onDatachange中聲明並初始化textviews會起作用...但是我希望在調用此方法之前textviews不可見...而在調用此方法時我希望它可見...我怎樣才能做到這一點?

發布您遇到的錯誤,

使您的textview最終,

並記住在命名變量時要遵循慣例(您的textview應該以小寫字母開頭)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM