21

When using the below code, I get an error "Couldn't resolve resource @id/item1" Why is this? id/item1 is added before I use it, so I'm not sure why this is coming up.

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

    <ImageView
        android:id="@+id/item1"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:src="@drawable/noimage" />
    <TextView         
        android:id="@+id/item2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Title"
        android:padding="3dip" 
        android:textSize="20dip"
        android:layout_toRightOf="@id/item1"/>
    <TextView         
        android:id="@+id/item3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Content"
        android:padding="3dip" 
        android:textSize="20dip"
        android:layout_below="@id/item1"/>

</RelativeLayout>
Onik
  • 19,396
  • 14
  • 68
  • 91
kieblera5
  • 577
  • 2
  • 5
  • 7

7 Answers7

19

I don't have this error with your code.

Make sure you don't have errors in other resources (layouts, values, drawables, etc.). And then clean/refresh/build the project

inazaruk
  • 74,247
  • 24
  • 188
  • 156
  • 7
    I had the same error and was able to fix it by restarting eclipse (cleaning didn't help). Although for me the graphical relative layout editor crashed while I was dragging stuff around. – Jason Axelson Mar 19 '12 at 07:05
  • 11
    when in doubt... restart eclipse. the answer to probably half of my android-related problems -_- – Alex Lockwood Mar 25 '12 at 01:59
  • 3
    For those using Android Studio and cleaning didn't help, restarting fixed the problem for me too. – craned Jun 12 '14 at 22:50
  • 1
    Same here, tried Build>Clean Project + Build>Make Project or Build>Rebuild Project - nothing helped. Restarting Android Studio fixed it. – Philipp Gächter Jul 29 '14 at 15:06
14

As Jose said, sometimes Android Studio just gets crazy. But a restart ain't always enough.

Invalidate your caches and restart.

File -> Invalidate Caches / Restart... -> Invalidate and Restart

Menu Selection enter image description here

Wait until AS has completely restarted and rebuilt. Hopefully it'll behave logically.

SMBiggs
  • 11,034
  • 6
  • 68
  • 83
1

RelativeLayout “Couldn't resolve resource… ... you need to define String Resources in res/values/strings.xml

0

I have the same error when I import a project form other devices. Sometimes, the reason of this error is the wrong android SDK path in your current developing environment.

enter image description here

You need change your local android SDK path.

1 Open local.properties

enter image description here

2 Replace the sdk.dir path use your local SDK path.

enter image description here

3 Refresh your project and Close your Android Studio.

enter image description here

4 Open the Android Studio, Everything is OK.

enter image description here

saneryee
  • 3,239
  • 31
  • 22
0

Had this problem on 2 computers with Android Studio. Helped to open Gradle and re-sync the project (shown on the screenshot posted previously) Resync

Ruzard
  • 1,167
  • 3
  • 16
  • 33
0

Some times the IDE gets crazy. :) Just restart the Android Studio, as said before by @JasonAxelson, @AlexLockwood, @craned and @PhilippGächter.

Jose Raul Barreras
  • 849
  • 1
  • 13
  • 19
-1

This happens when you forget to save the /res/values/strings.xml