String.format()中的Android Studio“格式错误的参数类型错误”

时间:2021-09-07 15:01:23
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

在最后一次转换aobj中获取Android Studio中的错误

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

“在time_score中格式化参数#1的参数类型错误:转换'd',接收的Object(方法调用中的参数#2)”

1 个解决方案

#1


0  

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

我认为这是因为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));

试试这个:textview.setText(String.format(s,i));

Hope this helps.

希望这可以帮助。

#1


0  

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

我认为这是因为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));

试试这个:textview.setText(String.format(s,i));

Hope this helps.

希望这可以帮助。