2013-06-20 63 views
0

使用字符串資源我試圖從IntentService獲得字符串資源值,如下所示:錯誤在IntentService

String errorTitle = getResources().getString(R.string.no_Internet_connection_error_title); 

但它顯示了一個錯誤no_Internet_connection_error_title cannot be resolved or is not a field

當我鍵入R.string.時,eclipse顯示了一個android定義的字符串列表,這個字符串不是由我定義的。

我在活動中使用字符串資源,但無法在IntentService中使用。

+3

導入R類別'進口com.example.androidtest .R;' –

+0

請刪除R.String騙取並導入您的R.class文件 – abhi

+0

可能是一個錯誤的導入。您可以使用前綴(包名稱)以確保您使用的是正確的包。如果你使用它,它會起作用嗎? 'getResources()。getString(yourproject.package.name.R.string.no_Internet_connection_error_title)' – Zhar

回答

3

我認爲其中一位評論者會發表一個答案。但因爲他們沒有我發佈它。

的解決方案是要麼導入R.java文件中使用包名:

import com.android.myApp.R; 

或者使用全包名稱來獲得字符串:

getResources().getString(com.android.myApp.R.string.no_Internet_connection_error_title); 
+0

你有沒有提到它在爲你工作的評論? – moDev