2015-06-06 96 views
0

我在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
  • 我试图改变compileSdkVersionbuildToolsVersiontargetSdkVersion
  • 我试着加入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仍然存在同样的问题。

+0

你有没有检查资源上是否有错误?或尝试重建你的项目。 –

+0

你需要检查你的资源文件。可能有一些格式错误或资源错误。 – Boggartfly

+0

显示您的strings.xml文件。 –

回答

1

因此,在尝试了很多与R相关的问题后,我查看了logCat,发现strings.xml文件中存在问题。显然,我忘了加上逃生标志,这引起了问题,所以这是我有什么之前:

<string name="negativeCups">You can't have negative number of cups of coffee<string> 

,这是固定的版本:

<string name="negativeCups">You can\'t have negative number of cups of coffee<string> 

就是这样..那是什么引起的这个问题现在已经修复了,谢谢大家!

1

The values part

创建两个不同的文件夹一样在图片中的值,一个是默认的(英文)的所有值文件和strings.xml中的英文字符串,并呼吁值一个叫值,他只有希伯来文的string.xml文件。

+0

它看起来不像这里面的Android Studio,但在Finder中,它和你描述的一样。我得到了'values'文件夹和'values-he'文件夹,文件夹中的文件和预期的一样(他在希伯来语文件夹和常规文件夹中的常规文件) –

+0

这是一张我在互联网上发现的图片,它来自eclipse,但它对于android-studio – Chris

+2

是一样的请注意:'Java使用了几个不赞成使用的双字母代码。希伯来语(“he”)语言代码被改写为“iw”,印度尼西亚语(“id”)改为“in”,意第绪语(“yi”)改写为“ji”。参考:http://developer.android。 com/reference/java/util/Locale.html –