Here’s my problem.
I’m currently setting up a relative Layout for a TicTacToe-Game.
It consists of 9 ImageButtons, and 8 Views which I use to get the grid.
Either I have errors in my xmlfile, saying “no ressource found”(even if id’s are correctly build into my r.class) or the errors disappear when I retype my layout referrences to other view. But if I retype it, clean project and build it again, eclipse lets my R.class disappear.
Here my XML-File:
`<RelativeLayout 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:background="@drawable/notepad2" >
<View
android:layout_width="5dp"
android:layout_height="160dp"
android:background="#FF0000"
android:layout_toLeftOf="@id/hor2"
android:id="@+id/vert1"
/>
<View
android:layout_width="5dp"
android:layout_height="160dp"
android:background="#FF0000"
android:layout_toLeftOf="@id/hor3"
android:id="@+id/vert2"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld4"
android:layout_above="@id/feld4"
android:id="@+id/hor1"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld5"
android:layout_above="@id/feld5"
android:id="@+id/hor2"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld6"
android:layout_above="@id/feld6"
android:id="@+id/hor3"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld4"
android:layout_below="@id/feld4"
android:id="@+id/hor4"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld5"
android:layout_below="@id/feld5"
android:id="@+id/hor5"
/>
<View
android:layout_width="50dp"
android:layout_height="5dp"
android:background="#FF0000"
android:layout_alignLeft="@id/feld5"
android:layout_below="@id/feld6"
android:id="@+id/hor6"
/>
<ImageButton
android:id="@+id/feld1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toLeftOf="@id/vert1"
android:layout_alignTop="@id/vert1"
/>
<ImageButton
android:id="@+id/feld2"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_above="@id/hor2"
android:layout_alignLeft="@id/hor2"
/>
<ImageButton
android:id="@+id/feld3"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toRightOf="@id/vert2"
android:layout_alignTop="@id/vert2"
/>
<ImageButton
android:id="@+id/feld4"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toLeftOf="@id/vert1"
android:layout_alignTop="@id/feld5"
/>
<ImageButton
android:id="@+id/feld5"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_centerInParent="true"
/>
<ImageButton
android:id="@+id/feld6"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toRightOf="@id/vert2"
android:layout_alignTop="@id/feld5"
/>
<ImageButton
android:id="@+id/feld7"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toLeftOf="@id/vert1"
android:layout_below="@id/hor4"
/>
<ImageButton
android:id="@+id/feld8"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toRightOf="@id/vert1"
android:layout_below="@id/hor4"
/>
<ImageButton
android:id="@+id/feld9"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/leer"
android:contentDescription="@string/feld"
android:layout_toRightOf="@id/vert2"
android:layout_below="@id/hor4"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/winners"
android:text="@string/winner"
android:layout_alignParentBottom="true"
android:textColor="#FFFFFF"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/anotherGame"
android:visibility="invisible"
android:layout_above="@id/winners"
android:text="@string/newGameButton"
/>
`
Anyone an idea how to fix?
I already tried the usual. Corrected the ‘mistakes’ in the xml file, cleaned project, built it again and so on. Nothing worked.
While Sam is on the right track, it is actually bad practice to user
@+id/when you are not setting theandroid:idattribute.@+id/actually tries to add that id to your R file if it does not already exist. This can cause problems where you remove the element that another one aligns based on but an error will not be thrown since you are using@+id/Instead, you should define the layouts above views that align based on them in your xml file. For Example,
winnersshould go belowanotherGameIf you absolutely cannot get around having all views declared above the views that align based on them, you can fall back on using
@+id/