2011-05-19 60 views
1

我經歷從機器人平局本教程: http://www.droiddraw.org/tutorial3.html收到錯誤消息編譯Android項目

,當我嘗試編譯Eclipse中的代碼,我得到這個錯誤:

[2011-05-18 20:09:23 - DroidDrawTutorial1] /home/ollie/workspace/DroidDrawTutorial1/res/layout/main.xml:8: error: Error: No resource found that matches the given name (at 'entries' with value '@arrays/items'). 

這裏是RES /佈局/ main.xml中的內容:

?xml version="1.0" encoding="utf-8"?> 
<AbsoluteLayout 
android:id="@+id/widget29" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<ListView 
android:id="@+id/widget30" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:entries="@arrays/items" 
android:layout_x="0px" 
android:layout_y="2px" 
> 
</ListView> 
</AbsoluteLayout> 

在這裏被RES /值/ arrays.xml的內容:

<?xml version="1.0" encoding="utf-8" ?> 
<resources> 
<string-array name="items"> 
<item>item1</item> 
<item>item2</item> 
<item>item3</item> 
</string-array> 
</resources> 

回答

3

嘗試,而不是

android:entries="@array/items" 

它相當於R.array.items。該陣列的資源總是由它的資源名稱叫,獨立的XML的文件名定義它:

http://developer.android.com/guide/topics/resources/string-resource.html#StringArray

字符串數組

的字符串數組,可以從應用程序中引用。

注意:字符串數組是使用名稱屬性(而不是XML文件的名稱)中提供的值引用的簡單資源。因此,您可以在一個元素下將字符串數組資源與其他簡單資源結合在一個XML文件中。

+0

本教程中的文本不一致。我認爲@陣列只需要匹配文件的名稱;在我的情況下是arrays.xml。 – opike 2011-05-19 04:10:08

+1

你確實是正確的 - 這就是我依靠我的直覺得到的。謝謝你的幫助。 – opike 2011-05-19 04:20:06

+0

不,如果你從教程中獲得它,它肯定是一個錯字。文件名不相關。看到我更新的答案。編輯:有時文檔有幫助;) – Aleadam 2011-05-19 04:21:04