user2612538
user2612538

Reputation: 21

problems with R - ANDROID

when i create a layout called " 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>

when i go to the main to create a button " button = (Button) findViewById(R.id.button); " i have an error , i cant find the button in R.id and same for the spinner the id dont exist in R.id

help me plz

Upvotes: 2

Views: 104

Answers (3)

Delgado
Delgado

Reputation: 226

Try to verify that there is no errors in your XML files,than try to clean the project.

Upvotes: 0

NightSkyCode
NightSkyCode

Reputation: 1141

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.

Upvotes: 3

Jonathan
Jonathan

Reputation: 3457

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.

Upvotes: 3

Related Questions