Reputation: 587
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>
Upvotes: 21
Views: 45573
Reputation: 11688
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
Wait until AS has completely restarted and rebuilt. Hopefully it'll behave logically.
Upvotes: 14
Reputation: 859
Some times the IDE gets crazy. :) Just restart the Android Studio, as said before by @JasonAxelson, @AlexLockwood, @craned and @PhilippGächter.
Upvotes: 0
Reputation: 1359
Had this problem on 2 computers with Android Studio. Helped to open Gradle and re-sync the project (shown on the screenshot posted previously)
Upvotes: 0
Reputation: 3405
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.
You need change your local android SDK path.
1 Open local.properties
2 Replace the sdk.dir path use your local SDK path.
3 Refresh your project and Close your Android Studio.
4 Open the Android Studio, Everything is OK.
Upvotes: 0
Reputation: 11
RelativeLayout “Couldn't resolve resource… ... you need to define String Resources in res/values/strings.xml
Upvotes: 1
Reputation: 74780
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
Upvotes: 19