-3

My file strings.xml looks like the following:

<resources>
    <string name="app_name">BootIntervals</string>
    <string name="action_settings">Settings</string>
    <string name="logname">"bi2.log"</string>
</resources>

and later I call a method

 logger.init(R.string.logname);

which takes a String as argument. However, I get the following error:

Error:(21, 15) error: method init in class MyLogger cannot be applied to given types;
required: String
found: int
reason: actual argument int cannot be converted to String by method invocation conversion

It does not matter if I use bi2.log or "bi2.log" in strings.xml. What do I make wrong this time? I do not understand why R.string.logname is an integer...

Alex
  • 41,580
  • 88
  • 260
  • 469

2 Answers2

4

try this

this.getResources().getString(R.string.logname)
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
Mansi Salvi
  • 247
  • 1
  • 7
2

You have to use

getString(yourResourceId);

In your case, something like this

logger.init(getString(R.string.logname));
Victor Hugo Montes
  • 1,270
  • 1
  • 17
  • 28