I'm using Twitter4J with the Twitter API to retrieve some Tweets (also called statuses) from Twitter.
I need to temporarily store these Statuses to a SQL database. The way that I do this is by converting the Status to a JSON String
statusItem.setmStatus(TwitterObjectFactory.getRawJSON(status));
Where status is a Status object, part of Twitter4J's library and statusItem is my own custom item.
However, when I save this statusItem to my database:
public void createStatusItem(StatusItem mStatus) {
Log.d("StatusDBHelper","createStatusItem");
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(StatusItem.KEY_status, mStatus.mStatus);
values.put(StatusItem.KEY_date, mStatus.mDate);
values.put(StatusItem.KEY_user, mStatus.mUser);
db.insert(StatusItem.TABLE, null, values);
db.close();
}
I try to retrieve the StatusItem later like so:
status = TwitterObjectFactory.createStatus(statusItem.getmStatus());
However, statusItem.getmStatus is always null!! When I try to retrieve it from the database, it's too large so it doesn't get save into StatusItem's mStatus field!
How do I overcome such an issue in storing Statuses from Twitter into my SQL database for Android??
It turns out, the null issue was occuring much sooner than the point at which I was saving my status to my statusitem.
For some reason:
TwitterObjectFactory.getRawJSON(status);
returns null no materr what. As a result, I turned to Google's GSON parser and converted it to a JSON object that way.
Clearly, TwitterObjectFactory has some issues.