我試圖從服務器獲取該{"status": [{"RegistrationID":"4"}]}
值並保存在sharedpreferences該值但被拋出NullPointerException異常,這是我努力的代碼...正在從服務器單個值並將其保存到sharedpreferences
JSONObject o = new JSONObject(result);
JSONObject obj = o.optJSONObject("status");
String uid = obj.optString("RegistrationID");
Log.e("RegistrationID", uid);
AvailableItems set = new AvailableItems();
set.sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String value = set.sp.getString("RegistrationID", uid);
SharedPreferences.Editor editor = set.sp.edit();
editor.putString("first", value);
editor.commit();
異常顯示在這一行`String uid = obj.optString(「RegistrationID」);'
@hardik vyas現在檢查.... –
亞其右... –
什麼類型的變量是'結果'?它是一個字符串或任何其他格式 –