10 桁の数字である Facebook ID を含む文字列から「長い」値を取得しようとしています。私の関数は次のようになります。
@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