gpt4 book ai didi

java - 在 strings.xml 中使用长值时,Lint 给出 "Wrong format type"

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:04:27 27 4
gpt4 key购买 nike

我的项目在 strings.xml 中使用类似于以下的字符串声明:

<string name="file_size">File Size (%1$dMB)</string>

在我的代码中,我正在使用

getResources().getString(R.string.file_size, getFileSize());

其中 getFileSize() 返回一个 long。 Lint 给我这个错误:

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

这是怎么回事? Android 文档说:

enter image description here

最佳答案

看起来像是 lint 规则中的错误。查看 StringFormatDetector 的来源:

// Numeric: integer and floats in various formats
case 'x':
case 'X':
case 'd':
case 'o':
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
case 'a':
case 'A':
valid = type == Integer.TYPE
|| type == Float.TYPE;
break;

关于java - 在 strings.xml 中使用长值时,Lint 给出 "Wrong format type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23960019/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com