我试图从包含 Facebook ID 的字符串中获取“长”值,这是一个10 位数字。这是我的函数的样子:
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
try {
final long opponentId;
opponentId = jsonArray.getJSONObject(position).getLong("uid");
String opponentName = jsonArray.getJSONObject(position).getString("name");
Toast.makeText(this, "UID: " + opponentId + "\n" + "Name: " + opponentName, Toast.LENGTH_SHORT).show();
SharedPreferences myPrefs = getSharedPreferences("user", MODE_WORLD_READABLE);
String playerUidString = myPrefs.getString("uid", null);
if (playerUidString == null) {
Log.d(GlobalVars.TAG, "Empty UID");
return;
}
Log.d(GlobalVars.TAG, "ID: " + playerUidString);
Log.d(GlobalVars.TAG, "ID Long: " + String.valueOf(Long.getLong(playerUidString)));
// long player_id = Long.getLong(playerUidString);
// new GameRequest(getBaseContext(), player_id, opponentId);
} catch (JSONException e) {
Log.d(GlobalVars.TAG, e.getMessage());
}
}
通常,我会设置 long player_id 等于 playerUidString 到 long 的转换,但 Long.getLong(playerUidString) 结果为 null,而 playUidString 等于 10 位 ID 号。为什么会发生这种情况?
编辑:我的 Log.d 输出:
06-29 11:06:37.823: D/I See It(16053): ID: 1089490706
06-29 11:06:37.823: D/I See It(16053): ID Long: null