본문 바로가기
개발자/Android

[Android] error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?

by Alex.K 2014. 11. 13.
반응형

[Android] error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?


안드로이드 개발을 하면서 언어 리소스 관리의 중요성을 느끼게 된 후, 모든 언어 리소스는 string.xml 에 기입하고 있는데 어느날 위와 같은 에러가 발생했다.


에러는 String.format을 사용할 때 흔히 String.format("테스트 1 값 : %d , 테스트 2 값 : %d", 1, 2); 를 사용하게 되는데 이 부분을 String.xml에서 그대로 사용하게 되면 발생하는 에러이다.


에러 해결 방법은 2가지가 있는데,


1. <string name="test_format">테스트 1값 : %1$d, 테스트 2 값 : %2$d</string>

   위와같이 포맷 형식에 1$ , 2$ ... 의 순서를 붙여주는 방법


2. <string name="test_format" formatted="false">테스트 1 값 : %d, 테스트 2 값 : %d</string>

   속성에 formatted="false 를 추가하면 에러는 사라진다.

반응형

댓글