Android Studio: Error parsing XML & URI is not reg

2019-01-18 02:26发布

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... :)

7条回答
Summer. ? 凉城
2楼-- · 2019-01-18 02:47

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

查看更多
狗以群分
3楼-- · 2019-01-18 02:48

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.

查看更多
Ridiculous、
4楼-- · 2019-01-18 02:50

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.

查看更多
Summer. ? 凉城
5楼-- · 2019-01-18 02:51

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.

查看更多
冷血范
6楼-- · 2019-01-18 02:51

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!

查看更多
ら.Afraid
7楼-- · 2019-01-18 02:54

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>
查看更多
登录 后发表回答