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

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

PutParcable 時對象丟失數據

PutParcable 時對象丟失數據

C#
慕俠2389804 2023-05-13 16:06:44
我創建了一個用戶類并像這樣初始化它:User MyUser = new User("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");然后我用用戶數據填充對象并將其傳遞給另一個活動,我這樣做是這樣的:Intent intent = new Intent(this, typeof(MyActivity));Bundle bundlee = new Bundle();bundlee.PutParcelable("MyUser", MyUser); // Persist user class to next activityintent.PutExtra("TheBundle", bundlee);StartActivity(intent);   然后我在其他活動中檢索用戶數據,如下所示:// I initialize a variable againUser MyUser = new User("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");MyUser = bundlee.GetParcelable("MyUser") as User;我得到了除地址、城市和州之外的所有數據。很奇怪......我在代碼中放置了斷點,當我把它放在包中時,它就在那里,但是當我把它拿出來時,這三個字段是空字符串。
查看完整描述

1 回答

?
Helenr

TA貢獻1780條經驗 獲得超4個贊

我認為您在這里遇到了一些命名問題??催@部分


public User(string Username, string Password, string Firstname, string MiddleInitial, string Lastname, string Suffix,

            string address, string city, string state, string Zip, string Zip4, string Homephone, string Cellphone, string Workphone, 

            string NationalOrgn, string Country, string Company, string Section, string Department, string Usertype, 

            string Emailaddress)

        {

            this.mUsername = Username;

            this.mPassword = Password;

            this.mFirstname = Firstname;

            this.mMiddleInitial = MiddleInitial;

            this.mLastname = Lastname;

            this.mSuffix = Suffix;

            this.mAddress = Address;

            this.mCity = City;

            this.mState = State;

            this.mZip = Zip;

            this.mZip4 = Zip4;

            this.mHomephone = Homephone;

            this.mCellphone = Cellphone;

            this.mWorkphone = Workphone;

            this.mNationalOrgn = NationalOrgn;

            this.mCountry = Country;

            this.mCompany = Company;

            this.mSection = Section;

            this.mDepartment = Department;

            this.mUsertype = Usertype;

            this.mEmailaddress = Emailaddress;

        }

特別是這個:


this.mAddress = Address;

this.mCity = City;

this.mState = State;

正確的方法是:


this.mAddress = address;

this.mCity = city;

this.mState = state;

你實際上沒有使用你的參數(至少這三個)!這個“錯誤”有點意思,因為你的編譯器沒有抱怨。那是因為你實際上是在自己分配你的屬性(=null),這是正確的,但肯定不是這里的意圖;)!


將其更改為上面的應該可以解決問題。


查看完整回答
反對 回復 2023-05-13
  • 1 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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