[英]Can't pass an int to setMessage(String) method
為什么我會在這句話中出現編譯錯誤?
this.message.setMessage(R.string.game_over);
錯誤消息:
The method setMessage(String) in the type Messages is not applicable for the arguments (int)
我想使用我的res中存在於字符串文件中的字符串。 我知道arg是int
但這是我在網站上閱讀的方式
int是一個resourceID。 您必須獲取ID表示的String:
this.message.setMessage(getResources().getString(R.string.game_over));
setMessage
方法期望接收String
。 但是,您要發送一個整數。
更具體地說,您將向它發送整數,該整數是字符串的資源鍵。 要獲得所需的字符串,您需要執行以下操作:
Context myContext = getApplicationContext();
this.message.setMessage(myContext.getString(R.string.game_over));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.