Anguraj
Anguraj

Reputation: 935

Android Studio "Wrong argument type for formatting Error" in String.format()

TextView textview = (TextView)findViewById(timeScore);
    i = (int)(gridView.getTime() / 1000L);
    String s = getString(time_score);
    Object aobj[] = new Object[1];
    aobj[0] = Integer.valueOf(i);
    textview.setText(String.format(s, aobj));

Getting Error in Android Studio in last conversion aobj

"Wrong Argument type for formatting argument #1 in time_score: conversion 'd', recevied Object (argument #2 in method call)"

Upvotes: 5

Views: 6577

Answers (1)

justHooman
justHooman

Reputation: 3054

I think it's because of textview.setText(String.format(s, aobj));

Your string format require integer value but you pass a array to it.

Try this: textview.setText(String.format(s, i));

Hope this helps.

Upvotes: 5

Related Questions