我在strings.xml
文件中添加了一個翻譯,所以現在我有2 strings.xml
文件,一個用希伯來語和一個用英語(原文)。 後,我做了,突然在MainActivity.java
文件,每一個有代碼R
時,它顯示爲紅色,並說Android Studio在翻譯strings.xml後無法解析符號'R'
Cannot resolve symbol 'R'
我試過其他職位所有的答案,並沒有幫助:
- 我試着清理Gradle並同步它。
- 沒有XML錯誤
- 將
import android.R;
錯誤消失,但現在將顯示所有的XML文件的名稱(例如toastText = getString(R.string.negativeCups);
同樣的錯誤後,negativeCups
爲紅色,並顯示此錯誤。 - 我試圖重新啓動的Android工作室
- 我嘗試添加
import com.howtoevery.justjava.R;
- 沒有與大寫字母命名的文件的文件夾
Res
- 我試圖改變
compileSdkVersion
,buildToolsVersion
和targetSdkVersion
- 我試着加入
import android.R.*
一般情況下,我試過this後的每個答案,但沒有爲我工作。
原始strings.xml
文件中的代碼:
<resources>
<string name="app_name" translatable="false">Just Java</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="quantity">Quantity</string>
<string name="order">Order</string>
<string name="add">Add another cup of coffee to your purchase</string>
<string name="reset">Reset calculation</string>
<string name="decrease">remove 1 cup</string>
<string name="ordering">You are going to order</string>
<string name="ordering_cups_price">cups of coffee at a price of</string>
<string name="empty_order">You can't order nothing, please buy at least 1 cup of coffee</string>
<string name="resetted">Cups of coffee is already reset.</string>
<string name="negativeCups">You can't have negative number of cups of coffee</string>
</resources>
的翻譯代碼:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="add">תוסיף עוד כוס קפה להזמנה</string>
<string name="decrease">תסיר כוס אחת</string>
<string name="hello_world">שלום עולם!</string>
<string name="order">הזמן!</string>
<string name="quantity">כמות</string>
<string name="reset">אפס כמות</string>
<string name="action_settings">הגדרות</string>
<string name="ordering">אתה עומד להזמין</string>
<string name="ordering_cups_price"> כוסות קפה במחיר של </string>
<string name="empty_order">מה אתה פסיכי? אי אפשר להזמין כלום</string>
<string name="resetted">משעמם לך? לחצת כבר איפוס יא חופר</string>
<string name="negativeCups">טוב מה נהיה?? אתה רוצה כבר למכור כוסות?</string>
</resources>
更新: 我甚至與本地化的文件中刪除的文件夾strings.xml
仍然存在同樣的問題。
你有沒有檢查資源上是否有錯誤?或嘗試重建你的項目。 –
你需要檢查你的資源文件。可能有一些格式錯誤或資源錯誤。 – Boggartfly
顯示您的strings.xml文件。 –