第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

NullPointerException 從 Firebase 數(shù)據(jù)庫中檢索數(shù)據(jù)

NullPointerException 從 Firebase 數(shù)據(jù)庫中檢索數(shù)據(jù)

侃侃無極 2022-06-08 17:28:12
我正在嘗試從 Firebase 數(shù)據(jù)庫中檢索 9 個(gè)布爾變量和一個(gè) int 變量,但是每次我運(yùn)行我的應(yīng)用程序時(shí),它都會(huì)給我一個(gè)空指針異常它來自一個(gè) Android 應(yīng)用程序,我設(shè)置了一個(gè)模型頁面,我設(shè)置了 getter 和 setter 方法,但它一直在檢索空指針 exeption 這是模型public class ButtonInformation {    private boolean Button1=false;    private boolean Button2=false;    private boolean Button3=false;    private boolean Button4=false;    private boolean Button5=false;    private boolean Button6=false;    private boolean Button7=false;    private boolean Button8=false;    private boolean Button9=false;    private int ApeOmaggio=0;    public ButtonInformation(){    }    public ButtonInformation(boolean button1, boolean button2, boolean button3, boolean button4, boolean button5, boolean button6, boolean button7, boolean button8, boolean button9, int apeOmaggio) {        Button1 = button1;        Button2 = button2;        Button3 = button3;        Button4 = button4;        Button5 = button5;        Button6 = button6;        Button7 = button7;        Button8 = button8;        Button9 = button9;        ApeOmaggio = apeOmaggio;    }    public boolean getButton1(){        return Button1;    }    public void setButton1(boolean Button1){        this.Button1 = Button1;    }    public boolean getButton2(){        return Button2;    }    public void setButton2(boolean Button2){        this.Button2 = Button2;    }    public boolean getButton3(){        return Button3;    }    public void setButton3(boolean Button3){        this.Button3 = Button3;    }    public boolean getButton4(){        return Button4;    }    public void setButton4(boolean Button4){        this.Button4 = Button4;    }    public boolean getButton5(){        return Button5;    }    public void setButton5(boolean Button5){        this.Button5 = Button5;    }    public boolean getButton6(){        return Button6;    }    public void setButton6(boolean Button6){        this.Button6 = Button6;    }    public boolean getButton7(){        return Button7;    }
查看完整描述

2 回答

?
慕姐4208626

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊

您可以直接將您的模型類與 Firebase 響應(yīng)數(shù)據(jù)進(jìn)行映射。您不必手動(dòng)設(shè)置模型類中的每個(gè)數(shù)據(jù)。


如果您的數(shù)據(jù)將從 Firebase 中成功檢索,則此代碼將起作用,請嘗試以下代碼。


@Override

    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_clienti);

        Utente=findViewById(R.id.tvUtente);

        ApeOmaggio = findViewById(R.id.tvOmaggio);

        bInfo= new ButtonInformation();

        img1=findViewById(R.id.img1);

        img2=findViewById(R.id.img2);

        img3=findViewById(R.id.img3);

        img4=findViewById(R.id.img4);

        img5=findViewById(R.id.img5);

        img6=findViewById(R.id.img6);

        img7=findViewById(R.id.img7);

        img8=findViewById(R.id.img8);

        img9=findViewById(R.id.img9);

        mAuth=FirebaseAuth.getInstance();

        mFirebaseDatabase = FirebaseDatabase.getInstance();

        user = mAuth.getCurrentUser();

        utenteLog = user.getDisplayName();

        mail = user.getEmail();

        mailNoSpace=mail.replaceAll("\\.","");

        Utente.setText(utenteLog);

        myRef=mFirebaseDatabase.getReference(mailNoSpace);

        myRef.addValueEventListener(new ValueEventListener()

        {

            @Override

            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            ButtonInformation buttonInformation = dataSnapshot.getValue(ButtonInformation.class);

                showData(buttonInformation);

            }

            @Override

            public void onCancelled(@NonNull DatabaseError databaseError) {


            }

        });


    }


    private void showData(ButtonInformation buttonInformation) {

        

            if (buttonInformation.getButton1()==true){

                img1.setImageResource(R.drawable.berry_icon);

            }else{

                img1.setImageResource(R.drawable.radio_button);

            }

            if (buttonInformation.getButton2()==true){

                img2.setImageResource(R.drawable.berry_icon);

            }else{

                img2.setImageResource(R.drawable.radio_button);

            }

            if (buttonInformation.getButton3()==true){

                img3.setImageResource(R.drawable.berry_icon);

            }else{

                img3.setImageResource(R.drawable.radio_button);

            }

            if (buttonInformation.getButton4()==true){

                img4.setImageResource(R.drawable.berry_icon);

            }else{

                img4.setImageResource(R.drawable.radio_button);

            }

            if (buttonInformation.getButton5()==true){

                img5.setImageResource(R.drawable.berry_icon);

            }else{

                img5.setImageResource(R.drawable.radio_button);

            }

            if (buttonInformation.getButton6()==true){

                img6.setImageResource(R.drawable.berry_icon);

            }else{

                img6.setImageResource(R.drawable.radio_button);

            }

            if (buttonInformation.getButton7()==true){

                img7.setImageResource(R.drawable.berry_icon);

            }else{

                img7.setImageResource(R.drawable.radio_button);

            }

            if (buttonInformation.getButton8()==true){

                img8.setImageResource(R.drawable.berry_icon);

            }else{

                img8.setImageResource(R.drawable.radio_button);

            }

            if (buttonInformation.getButton9()==true){

                img9.setImageResource(R.drawable.berry_icon);

            }else{

                img9.setImageResource(R.drawable.radio_button);

            }

            ApeOmaggio.setText(Integer.toString(bInfo.getApeOmaggio()));


    }

查看完整回答
反對 回復(fù) 2022-06-08
?
牛魔王的故事

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊

在訪問 firebase 之前使用 if not null 條件?;蛘?,如果您已將子屬性更改為您的 firebase 項(xiàng)目,請檢查樹。



查看完整回答
反對 回復(fù) 2022-06-08
  • 2 回答
  • 0 關(guān)注
  • 126 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)