2015-06-06 56 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 –