Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lint gives "Wrong format type" when using long values in strings.xml

Tags:

java

android

lint

My project uses a string declaration in strings.xml similar to:

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

And in my code, I'm using

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

Where getFileSize() returns a long. Lint give me this error:

"Wrong argument type for formatting argument '#1' in file_size: conversion is 'd', received long (argument #2 in method call)"

What's going on here? The Android documentation says that:

enter image description here

like image 230
M Dapp Avatar asked May 30 '14 17:05

M Dapp


1 Answers

Looks like a bug in the lint rules. See the source for 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;
like image 156
matiash Avatar answered Sep 24 '22 23:09

matiash