Search code examples
androidlayoutfindviewbyid

FindViewById not detecting id


I'm having a strange issue in my Android Application. I'm not new in this world and i've never experienced a problem like this. In my xml i define some views. I can reference all of them from java but one. That one is this: android:id="@+id/mytextview".

I leave the whole code below.

Thanks in advance!

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Cover"
    android:background="#FFC125" >

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


        <TextView 
            android:id="@+id/usersite_title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hola"/>

        <View 
            android:id="@+id/line1"
            android:layout_marginTop="10dp"
            android:layout_width="fill_parent"
            android:layout_height="2dip"
            android:background="#FFFFFF"
            android:layout_below="@+id/usersite_title"/>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:orientation="horizontal"
            android:weightSum="6"
            android:layout_marginTop="20dp"
            android:layout_below="@+id/line1"
            android:id="@+id/layout1">

            <ImageView 
                android:id="@+id/userlogo"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:src="@drawable/ic_launcher"
                android:clickable="true"
                android:background="@drawable/imageborders" 
                android:layout_marginLeft="5dp" 
                android:layout_marginRight="5dp"/>

            <LinearLayout 
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:orientation="vertical"
            android:layout_weight="4"
            android:gravity="center">

                <TextView 
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="Actualmente tienes"/>

                <TextView 
                android:id="@+id/mytextview"
                android:layout_marginTop="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"/>

                <TextView 
                android:layout_marginTop="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="puntos acumulados"/>
            </LinearLayout>

        </LinearLayout>

        <View 
            android:id="@+id/line2"
            android:layout_marginTop="10dp"
            android:layout_width="fill_parent"
            android:layout_height="2dip"
            android:background="#FFFFFF"
            android:layout_below="@+id/layout1"/>

        <TextView 
           android:id="@+id/ultimospedidos"
           android:layout_marginTop="15dp"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_below="@+id/line2"
           android:gravity="center"
           android:text="Mis últimos pedidos"/>  

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:orientation="vertical"
            android:layout_below="@+id/ultimospedidos"
            android:id="@+id/scrollView1"
            android:gravity="center">

            <LinearLayout 
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:orientation="vertical">

            </LinearLayout>

        </ScrollView>

        <View 
            android:id="@+id/line3"
            android:layout_marginTop="10dp"
            android:layout_width="fill_parent"
            android:layout_height="2dip"
            android:background="#FFFFFF"
            android:layout_below="@+id/scrollView1"/>

        <Button 
            android:id="@+id/hacerpedido"
            android:layout_marginTop="10dp"
            android:layout_below="@+id/imageView1"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="Hacer pedido"
            android:layout_centerInParent="true"
            android:background="@drawable/CustomButton"/>

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_below="@+id/line3"
            android:src="@drawable/repartidor" />

    </RelativeLayout>

</ScrollView>

Solution

  • Are you seeing red cross mark on res folder? If so, Eclipse is unable to generate the R.java file, so first fix that error and then clean the project. Hope it solve your problem.