2

当我创建一个名为“ main.xml ”的布局时:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/button" />

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />
</LinearLayout>

当我去主创建一个按钮“按钮=(按钮)findViewById(R.id.button);”我有一个错误,我无法在R.id中找到按钮,并且对于不存在id的微调器来说也是如此身份证

请帮帮我

4

3 回答 3

3

Make sure you don't have any files, pictures, etc in your drawable or assets folder with capital letters, spaces, or dashes. Just use plane old lowercase. Also, try to clean your project. Go to project > clean. Then restart eclipse. Hope this helps. Also eclipse won't reconize any changes in XML files without saving first. Make sure to save after you add a button, ect.

于 2013-07-24T00:07:50.933 回答
3

You're probably importing the wrong version of R. There are two versions which exist: the static R class which exists in android.R and then there is also yourPackageName.R. If you import the former none of your Ids will be found.

于 2013-07-24T00:03:31.610 回答
0

尝试验证您的 XML 文件中没有错误,然后尝试清理项目。

于 2013-07-24T00:36:47.967 回答