亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 firebase 獲取名稱時 model_user 中獲取 null - AndroidX

從 firebase 獲取名稱時 model_user 中獲取 null - AndroidX

qq_花開花謝_0 2023-11-01 16:48:39
當我在 MainActivity 中時,當使用 model_user 從 firebase 設置用戶名時,我得到 null,這是我使用的代碼//MainActivity.xml<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"tools:context=".MainActivity"><com.google.android.material.appbar.AppBarLayout    android:layout_width="match_parent"    android:layout_height="wrap_content">    <androidx.appcompat.widget.Toolbar        android:id="@+id/Toolbar_Main"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@color/colorPrimaryDark"        android:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar">        <de.hdodenhof.circleimageview.CircleImageView            android:layout_width="30dp"            android:layout_height="30dp"            android:id="@+id/profile_image"            android:src="@drawable/profile_blank"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:id="@+id/username"            android:textSize="18sp"            android:layout_marginLeft="25dp"            android:textColor="#fff"            android:textStyle="bold"            android:layout_marginStart="25dp" />    </androidx.appcompat.widget.Toolbar>    <com.google.android.material.tabs.TabLayout        android:id="@+id/tab_layout"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="@color/colorPrimaryDark"        app:tabSelectedTextColor="#fff"        app:tabIndicatorColor="#fff"        app:tabTextColor="#fff"/></com.google.android.material.appbar.AppBarLayout><androidx.viewpager.widget.ViewPager    android:id="@+id/view_pager"    android:layout_width="match_parent"    android:layout_height="match_parent"</LinearLayout>
查看完整描述

2 回答

?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

刪除 getter-setter 并添加空構造函數


ModelUser.java


  public class ModelUser {

    public String id;

    public String username;

    public String imageURL;


    public ModelUser(String id, String username, String imageURL) {

        this.id = id;

        this.username = username;

        this.imageURL = imageURL;

    }


    public ModelUser() {

    }

    }

嘗試這個


查看完整回答
反對 回復 2023-11-01
?
慕運維8079593

TA貢獻1876條經驗 獲得超5個贊

它不需要刪除 setter getter,


那么從此


public class ModelUser {

private String id;

private String username;

private String imageURL;


public ModelUser(String id, String username, String imageURL) {

    this.id = id;

    this.username = username;

    this.imageURL = imageURL;

}



public String getId() {

    return id;

}


public void setId(String id) {

    this.id = id;

}


public String getUsername() {

    return username;

}


public void setUsername(String username) {

    this.username = username;

}


public String getImageURL() {

    return imageURL;

}


public void setImageURL(String imageURL) {

    this.imageURL = imageURL;

}

}


只需添加一個空的構造函數即可正常工作:)


public class ModelUser {

public String id;

public String username;

public String imageURL;


public ModelUser(String id, String username, String imageURL) {

    this.id = id;

    this.username = username;

    this.imageURL = imageURL;

}


//Add this

public ModelUser() {

}


public String getId() {

    return id;

}


public void setId(String id) {

    this.id = id;

}


public String getUsername() {

    return username;

}


public void setUsername(String username) {

    this.username = username;

}


public String getImageURL() {

    return imageURL;

}


public void setImageURL(String imageURL) {

    this.imageURL = imageURL;

}

}



查看完整回答
反對 回復 2023-11-01
  • 2 回答
  • 0 關注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號