Reputation: 21
An UnknownFormatConversionException is thrown on the calling of the insert function just after the for loop and the printing of the Log, i caught that exception but how to remove it? I do'nt know what the reason it happened,
try {
List<Status> timeline =
((YambaApp) getApplication()).getTwitter().getPublicTimeline();
for (Status status : timeline) {
Log.d(TAG, String.format("%s: %s", status.user.name,
status.text));
statusData.insert(status);
}
} catch (TwitterException e) {
Log.d(TAG,"Failed to access twitter service ",e);
} catch(NullPointerException a){
Log.d(TAG,"Pref had been changed and twitter object is null",a);
} catch (UnknownFormatConversionException u){
Log.d(TAG,"exception "+ u);
}
Here is the Code of the insert function:
public void insert(Status status){
db=dbHelper.getWritableDatabase();
ContentValues value= new ContentValues();
//converting BigInteger to String
BigInteger bi=status.id;
String status_id= new String(bi.toByteArray());
value.put(C_ID, status_id);
value.put(C_CREATED_AT, status.createdAt.getTime());
value.put(C_TEXT, status.user.name);
value.put(C_TEXT, status.text);
db.insert(TABLE, null, value);
}
Here is the complete stack trace of the thrown exception
10-10 06:05:22.648: E/AndroidRuntime(627): FATAL EXCEPTION: IntentService[RefreshService]
10-10 06:05:22.648: E/AndroidRuntime(627): java.util.UnknownFormatConversionException: Conversion: i
10-10 06:05:22.648: E/AndroidRuntime(627): at java.util.Formatter$FormatToken.unknownFormatConversionException(Formatter.java:1397)
10-10 06:05:22.648: E/AndroidRuntime(627): at java.util.Formatter$FormatToken.checkFlags(Formatter.java:1334)
10-10 06:05:22.648: E/AndroidRuntime(627): at java.util.Formatter.transform(Formatter.java:1440)
10-10 06:05:22.648: E/AndroidRuntime(627): at java.util.Formatter.doFormat(Formatter.java:1079)
10-10 06:05:22.648: E/AndroidRuntime(627): at java.util.Formatter.format(Formatter.java:1040)
10-10 06:05:22.648: E/AndroidRuntime(627): at java.util.Formatter.format(Formatter.java:1009)
10-10 06:05:22.648: E/AndroidRuntime(627): at java.lang.String.format(String.java:1998)
10-10 06:05:22.648: E/AndroidRuntime(627): at java.lang.String.format(String.java:1972)
10-10 06:05:22.648: E/AndroidRuntime(627): at com.example.yamba.StatusData$DbHelper.onCreate(StatusData.java:59)
10-10 06:05:22.648: E/AndroidRuntime(627): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:165)
10-10 06:05:22.648: E/AndroidRuntime(627): at com.example.yamba.StatusData.insert(StatusData.java:32)
10-10 06:05:22.648: E/AndroidRuntime(627): at com.example.yamba.RefreshService.onHandleIntent(RefreshService.java:32)
10-10 06:05:22.648: E/AndroidRuntime(627): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
10-10 06:05:22.648: E/AndroidRuntime(627): at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 06:05:22.648: E/AndroidRuntime(627): at android.os.Looper.loop(Looper.java:137)
10-10 06:05:22.648: E/AndroidRuntime(627): at android.os.HandlerThread.run(HandlerThread.java:60)
10-10 06:05:22.968: W/IInputConnectionWrapper(627): showStatusIcon on inactive InputConnection
Upvotes: 1
Views: 296
Reputation: 95578
In your insert()
method change
String status_id= new String(bi.toByteArray());
to
String status_id = bi.toString();
Calling bi.toByteArray()
is going to return you a byte array containing the binary representation of the BigInteger
. You can't convert this into a String
properly the way you are doing it. Just use the provided toString()
method of BigInteger
.
Upvotes: 1