简体   繁体   中英

What is an “Unbound Prefix” in Android Studio/Java/XML?

I have an error that has cropped up, I can't figure out what is wrong. I'm following the lesson at https://developer.android.com/training/appbar/setting-up.html and everything is fine until I add the code

<android.support.v7.widget.Toolbar
   android:id="@+id/my_toolbar"
   android:layout_width="match_parent"
   android:layout_height="?attr/actionBarSize"
   android:background="?attr/colorPrimary"
   android:elevation="4dp"
   android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
   app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

Then it says the line

<android.support.v7.widget.Toolbar

is an unbound prefix. I have no clue what it wants me to do, and I can't find an explanation of " Unbound Prefix" on developer.android.com. Could someone please explain what I'm doing wrong?

It means that you're using an XML namespace prefix (such as android: and app: on the shown attribute names) without having declared it.

Add

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

to element (or any of its ancestors) that uses the android or app namespace prefixes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM