【发布时间】:2015-08-21 07:28:13
【问题描述】:
我在strings.xml 文件中添加了翻译,所以现在我有2 个strings.xml 文件,一个是希伯来文,一个是英文(原版)。
在我这样做之后,突然在MainActivity.java文件中,每次代码中有R时,它都会显示为红色并显示
Cannot resolve symbol 'R'
我尝试了其他帖子中的所有答案,但没有帮助:
- 我尝试清理 Gradle 并同步它。
- 没有 xml 错误
- 添加
import android.R;后错误消失,但现在所有xml 文件名都显示相同的错误(例如toastText = getString(R.string.negativeCups);,negativeCups为红色并显示此错误。 - 我尝试重启 Android Studio
- 我尝试添加
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 文件的文件夹,但我仍然遇到同样的问题。
【问题讨论】:
-
您检查资源是否有任何错误?或者尝试重建你的项目。
-
你需要检查你的资源文件。可能存在一些格式或资源错误。
-
显示您的两个 strings.xml 文件。
-
那些 strings.xml 文件被放置在两个单独的目录中,values 是英文的,values-he 是希伯来语的?
标签: java android xml android-studio