无法解析或不是一个字段(Android开发网站的记事本练习)

3 eclipse android notepad eclipse-plugin

我正在浏览android dev网站上的记事本练习,目前正在进行练习(在这里找到).

我走到教程的最后,发现我在主要的两个关于R文件关系的java文件中有几个错误,例如setContentView(R.layout.notes_list);menu.add(0, INSERT_ID,0, R.string.menu_insert);

我试过清洁和重新生成R.java无济于事.

这些也出现在练习的解决方案中,所以我认为它们是故意的错误,或者是我的日食,但我似乎无法修复它们,任何帮助都会非常感谢!

Sep*_*phy 7

布局文件夹中是否有布局notes_list.xml?在strings.xml中是否有一个名为menu_insert的字符串?这可能是问题所在,因为我认为他们没有在教程中给出所有内容......他们确实在解决方案中使用了它们:

<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
<ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<TextView android:id="@+id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/no_notes"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在values文件夹的strings.xml中:

<string name="menu_insert">Add Note</string>
Run Code Online (Sandbox Code Playgroud)

  • 然后,尝试检查类顶部的导入,有时这个愚蠢的Eclipse从android包导入R类并停止使用你的. (9认同)

And*_*ens 5

我想您可能必须小心如何使用ctrl-shift-O命令(自动插入文件顶部的"import"语句).可能是你得到了"import android.R;" 声明为"奖金".我评论了"import android.R;" 声明,一切都很好.