一个getter返回null,其他getter返回acctual值firebase

时间:2017-08-18 10:09:44

标签: android firebase firebase-realtime-database

我的firebase数据库或类中有一个非常奇怪的问题,其中只有一个getter不能像标题所暗示的那样工作。

这来自“CustomProtocolOther”类:

public class CustomProtocolOther implements Parcelable {
    public String pileID;
    public String dimHead;


    public CustomProtocolOther() {
    }
 public CustomProtocolOther(String pileID,
                            String dimHead,


    ) {

        this.pileID = pileID;
        this.dimHead = dimHead;

    }

    protected CustomProtocolOther(Parcel in) {

        pileID = in.readString();
        dimHead = in.readString();


    }

    public static final Creator<CustomProtocolOther> CREATOR = new Creator<CustomProtocolOther>() {
        @Override
        public CustomProtocolOther createFromParcel(Parcel in) {
            return new CustomProtocolOther(in);
        }

        @Override
        public CustomProtocolOther[] newArray(int size) {
            return new CustomProtocolOther[size];
        }
    };

    public void setPileID(String pileID) {
        this.pileID = pileID;
    }

    public String getPileID() {
        return pileID;
    }

    public void setDimHead(String dimHead) {
        this.dimHead = dimHead;
    }

    public String getDimHead() {
        return dimHead;
    }
  @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(pileID);
        parcel.writeString(dimHead);

    }
}

在另一个活动中,我试图像这样得到dimHead和pileID:

private void populateOtherTextViews() {
        mProtocolDatabaseReferenceOther = mProtocolDatabaseReference.child(pileID).child(other); // 7901337/1/_other

        mProtocolDatabaseReferenceOther.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                String s = protocolOther.getPileID();

                String p = protocolOther.getDimHead();
               }
}

但后者只返回null,我似乎无法弄清楚为什么getDimHead不起作用?我错过了什么?

当我运行程序时,我调试它发现dimHead的节点中有一个值,但是getter只返回null。 附件是firebase数据库的片段。

更新:protocolOther从intent中实例化onCreate:

 Intent intent = getIntent();
        EXISTING_PROTOCOL = intent.getBooleanExtra("ExitingProtocol", false);
        protocolOther = intent.getParcelableExtra("protocolOthers");
        protocolAmount = intent.getParcelableExtra("protocolAmounts");

Firebase data

0 个答案:

没有答案