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

一世执手 提交于 2021-01-27 15:02:20

问题


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)"


回答1:


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.



来源:https://stackoverflow.com/questions/31553910/android-studio-wrong-argument-type-for-formatting-error-in-string-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!