error reading xml string in java file

后端 未结 1 1517
清酒与你
清酒与你 2021-01-17 06:17

How to fix the error


R.string.Invalid_city_name


using the method

getstring(R. string.Invalid_city_name)

the same error what is

相关标签:
1条回答
  • 2021-01-17 06:32

    You need to use getString. It is a part of the COntext class:

    status = /*context.*/getString(R.string.Invalid_city_name));
    

    If you are in an activity, writing getString is enough. Otherwise, you need a Context or Activity to reference to.

    R.string.* is an integer, and you can't set a String to an Integer like that. You either need to add + "" or use Integer.toString(int)

    So to summarize:

    • Use getString to get String resources
    • -> getString is in the Context class. You either need a Context or an Activity to call to.
    0 讨论(0)
提交回复
热议问题