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

android, java, lint

Solution

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;

Problem

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:

Original source