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

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

如何在嘗試訪問 SystemPreferences 數(shù)據(jù)時找出應(yīng)用程序崩潰的原因

如何在嘗試訪問 SystemPreferences 數(shù)據(jù)時找出應(yīng)用程序崩潰的原因

森林海 2022-10-26 16:48:36
我正在嘗試在整個應(yīng)用程序中維護用戶 ID 和用戶名。我創(chuàng)建了一個名為 Session 的類,它將數(shù)據(jù)放置和接收到 SharedPreferences 并設(shè)置它工作得很好。我遇到的問題是當我去另一個活動中檢索它時。會話類構(gòu)造函數(shù) public Session(Context cntx) {        // TODO Auto-generated constructor stub        prefs = PreferenceManager.getDefaultSharedPreferences(cntx);    }添加用戶ID的會話類方法和檢索它的方法 public void setUserID(int userID) {        prefs.edit().putInt("userID", userID).apply();    }public int getID() {        int userID;        return userID = prefs.getInt("userID",0);    }在登錄時設(shè)置 ID StringRequest stringRequest = new StringRequest(Request.Method.POST, server_url, new Response.Listener<String>() {                    @Override                    public void onResponse(String response) {                        builder.setTitle("Server Response");                        builder.setMessage("Response :"+response);                        session = new Session(getApplicationContext());                        int responseInt = Integer.parseInt(response.trim());                        session.setUserID(responseInt);                        Intent myIntent = new Intent(LoginActivity.this, navActivity.class);                        startActivity(myIntent);                        finish();嘗試檢索該 ID 并放入 editText @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_my_jars);        session = new Session(getApplicationContext());        userID = (EditText) findViewById(R.id.userID);        builder = new AlertDialog.Builder(MyJars.this);        userID.setText(session.getID());我希望能夠提取該數(shù)據(jù)并將其發(fā)送到我的服務(wù)器,在那里我可以運行我的 PHP 腳本,就像我在其他活動中一樣,但這不合作。
查看完整描述

1 回答

?
猛跑小豬

TA貢獻1858條經(jīng)驗 獲得超8個贊

在這一行:

userID.setText(session.getID());

session.getID()是一個整數(shù),它被解釋為一個整數(shù)資源 ID,而不是您要設(shè)置的字符串文本userID
改成這樣:

userID.setText("" + session.getID());

或者

userID.setText(String.valueOf(session.getID()));


查看完整回答
反對 回復(fù) 2022-10-26
  • 1 回答
  • 0 關(guān)注
  • 87 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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