我在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文件。 –