我在string.xml
的字符串:格式化字符串參數計數錯誤
<string name="date_time_short">%2$d.%2$d. %1$s %2$d:%2$d</string>
現在我想從代碼中設置的值:
String.format(context.getResources().getString(R.string.date_time_short), day, month, at, hour, minute);
,但我得到的錯誤:
Wrong argument count, format string date_time_short requires 2 but format call supplies 5
所以它似乎有一個%1$s
代表一個字符串的問題。至少這是寫在文件here
If you need to format your strings using String.format(String, Object...), then you can do so by putting your format arguments in the string resource. For example, with the following resource:
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
In this example, the format string has two arguments: %1$s is a string and %2$d is a decimal number. You can format the string with arguments from your application like this:
那麼,爲什麼我收到此錯誤嗎?