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

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

PutParcable 時對象丟失數(shù)據(jù)

PutParcable 時對象丟失數(shù)據(jù)

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

1 回答

?
Helenr

TA貢獻1780條經(jīng)驗 獲得超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;

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


將其更改為上面的應(yīng)該可以解決問題。


查看完整回答
反對 回復 2023-05-13
  • 1 回答
  • 0 關(guān)注
  • 158 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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