11
Май
2012

Ошибка в findViewById

Button myButton = (Button) findViewById(R.id.button1);

Подчёркивает id, говорит, что нет его в R,

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int ic_launcher=0x7f020000;
    }
    public static final class layout {
        public static final int main=0x7f030000;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
    }
}

В R его реально нет, а в Layout/main.xml -

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

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <EditText
            android:id="@+id/A"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="numberDecimal" >

            <requestFocus />
        </EditText>



        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="* X"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="2"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=" +"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/B"
        android:layout_width="40dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10" />


    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="* X +"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/C"
        android:layout_width="40dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="10" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="= 0"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/TextView04"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="X"
        android:textAppearance="?android:attr/textAppearanceLarge" />




    <TextView
        android:id="@+id/TextView03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/TextView04"
        android:layout_alignBottom="@+id/TextView04"
        android:layout_toRightOf="@+id/TextView04"
        android:text="1"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/TextView05"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/TextView03"
        android:text=" = "
        android:textAppearance="?android:attr/textAppearanceLarge" />







    <TextView
        android:id="@+id/X1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/TextView05"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/TextView05"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="X"
        android:textAppearance="?android:attr/textAppearanceLarge" />


    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView5"
        android:layout_alignBottom="@+id/textView5"
        android:layout_toRightOf="@+id/textView5"
        android:text="2"
        android:textAppearance="?android:attr/textAppearanceSmall" />



    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/textView6"
        android:text=" = "
        android:textAppearance="?android:attr/textAppearanceLarge" />






    <TextView
        android:id="@+id/X2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/textView7"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/textView7"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>



<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Ответ" />

</LinearLayout>

кнопка есть, Ctrl + S нажал, проект пересоздал, всё равно одна и та же ошибка...

Источник: https://ru.stackoverflow.com/questions/109519/%D0%9E%D1%88%D0%B8%D0%B1%D0%BA%D0%B0-%D0%B2-findviewbyid

Тебе может это понравится...

Добавить комментарий