Why do I get compile error in this sentense?
this.message.setMessage(R.string.game_over);
Error messsage:
The method setMessage(String) in the type Messages is not applicable for the arguments (int)
I want to use string from my res which exist in string file. I know the arg is int
but this is the way I read in sites
The int is a resourceID. You have to get the String the ID represents:
this.message.setMessage(getResources().getString(R.string.game_over));
The method setMessage
expects to receive a String
. However, you are sending it an integer.
More specifically, you are sending it the integer which is the resource key to a string. To get the string you want, you will need to do something like:
Context myContext = getApplicationContext();
this.message.setMessage(myContext.getString(R.string.game_over));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.