1

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
7
  • 4
    Well, what was the exception? Commented Oct 9, 2012 at 18:28
  • UnknownFormatConversionException: conversion : i Commented Oct 9, 2012 at 18:37
  • 10-09 23:44:24.744: D/RefreshService(1493): exception java.util.UnknownFormatConversionException: Conversion: i Commented Oct 9, 2012 at 18:39
  • Is status.user.name a string? Your format statement expects a string %s Commented Oct 9, 2012 at 18:43
  • 1
    If you want to see exactly where the exception is being thrown, just remove your catch (UnknownFormatConversionException u) clause. Then you will get a stack trace that shows exactly where the exception is being thrown. Commented Oct 9, 2012 at 19:30

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.