27

After adding a new Activity to my project I get following error while compiling the layout

Gradle: Error parsing XML: not well-formed (invalid token)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical" >

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_password"
        android:text="<password>"/>
</LinearLayout>

"http://schemas.android.com/apk/res/android" is marked red and hovering pops following message up

URI is not registered ( Setting | Project Settings | Schemas and DTDs )

My Settings>Project Settings>Schemas and DTDs look like that: Settings>Project Settings>Schemas and DTDs

I already found some similar questions around here but nothing helped me to solve this issue. I hope someone has an idea... :)

Jonas
  • 1,432
  • 3
  • 20
  • 27

8 Answers8

18

I was having a similar issue. However, the comments did not assist me in the solution to this issue. This answer from this question actually solved my problem.

Summary:

Go to "File > Project Structure > Modules", click "add" and then click "android" and "apply/ok". That should solve anyone having a similar problem but the comments for this question are not helping you.

Community
  • 1
  • 1
prolink007
  • 33,872
  • 24
  • 117
  • 185
7

For me, the problem occured when I created my own subfolder for old code.

Specifically, Android Studio threw an error for all layout files that weren't in the default folder ../res/drawable/, but instead placed in my own subfolder ../res/drawable/backup.

Antimonit
  • 2,846
  • 23
  • 34
  • This fixed it! Thanks! I created the layout file in one folder above res/layout folder! – Sudhanshu Nov 22 '14 at 01:41
  • Also make sure that the new folder even if correctly named appears in build.gradle, per ` android { sourceSets { main { res { srcDirs 'src/main/res/old/drawable', ..... ` – Marc Spraragen Jun 17 '21 at 19:37
3

I got the same error for a long time and none of the answers I found online really helped me, or probably I wasn't looking the right way. At the end what I found out was the way I named the directory. So, I was trying to make the landscape layout for my app and named it layout_land. That kept showing me the URI is not registered error. I just had to change the directory name to layout-land.

Summary: No underscores in directory names!

moonyWolf
  • 79
  • 1
  • 8
1

My issue was creating new resource directory for some animation work. The files were .xml and I chose file type as "xml". I got this problem. Changing the file type to "values" and the problem went away. No idea why, could someone explain this to me? I'm using Android Studio on an iMac.

G O'Rilla
  • 268
  • 3
  • 5
1

GO to settings >Language&Framework >Schemas&DTD here add Uri used in your code.

Alpha
  • 156
  • 1
  • 10
0

Some special characters not allowed here. Directly to assign text then with warning

android:text="value"

@string file from get then avoid warning

android:text="@string/hello"

res/values/strings.xml

 <?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello!</string>
</resources>
0

For me this problem was gone when I have made following changes to my project structure on Android Studio. file->project structure ->SDK Location -> enable check mark for "Use embedded JDK (recommended). Hope this will help someone.

mask
  • 6,172
  • 3
  • 24
  • 23
0

First thing is go to the project folder in the Android studio and check for any folders which are created by you. It will show this error if you have created any folder on your own.

Santhosh s
  • 184
  • 1
  • 5