Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using strings.xml with %, $ and / and formatted

I added this line to my strings.xml, and it wont compile into R.
<string name="cl_txt_verinfo">List Version: %1$s\nAuthor: %2$s\nDate Created: %3$s\nLanguage: %4$s</string>

the errors i get are:

error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute? error: Unexpected end tag string

I want to ask how to make this work(i will use string.format later) and what does "formatted=false" do as opposed to not adding it/add it as true.

Edit: Clean and build is how I got this error. I got it so many times. But then I deleted an empty line and clean and rebuild everything is fine. This is really inconsistent and i have no idea what's causing the problem in the first place.

Two questions left:

  • Could someone still tell me what difference would "formatted=false" make?
  • How did I got this kind of behavior?(reporting error when there's none and i try to fix it by blowing things up and create a mess)

This is not the only time i had an error then it magically fixes itself. sometime i restart my adt and it resolves itself, but not this time sadly.

like image 880
Zuoanqh Avatar asked Jun 25 '14 08:06

Zuoanqh


1 Answers

If you added formatted=false then format specifiers(%,$ etc.) in your string resource are disabled and Formatter won't be able to recognize them. This will definitely help you.

For your 2nd problem there is no exact solution but what I do is delete gen and bin folder and then clean build project. What happens is every time you build a project, android checks if there is any new resource available and adds it to R.java and only after that you can use it.

like image 65
DCoder Avatar answered Sep 17 '22 17:09

DCoder