0

I am trying to use a cardview in my project, but while I am creating my XML file for my cardview, I keep getting the error

error: Error parsing XML: unbound prefix

but if I take out my cardview widget, it works. I looked at other questions and tried their responses but it isn't working. Does anyone see what is wrong with my code?

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="horizontal" >

     <android.support.v7.widget.CardView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_margin="8dp"
         card_view:cardCornerRadius="2dp" >
     </android.support.v7.widget.CardView>

 </LinearLayout>
3
  • 4
    you are missing a prefix for card_view. Commented Mar 17, 2015 at 5:05
  • Just missed that. Thank you Commented Mar 17, 2015 at 5:08
  • stackoverflow.com/questions/2221221/… Commented Mar 17, 2015 at 5:27

2 Answers 2

2
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:card_view="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="horizontal" >

 <android.support.v7.widget.CardView
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_margin="8dp"
     card_view:cardCornerRadius="2dp" >
 </android.support.v7.widget.CardView>

you should add xmlns:card_view="http://schemas.android.com/apk/res-auto" this for your parent layout

Sign up to request clarification or add additional context in comments.

2 Comments

it need not be for the parent layout you can have the namespace defined for cardview also
if u add it to the parent then u don't have to repeat with all views you adding.
2

Try this

<LinearLayout
xmlns:card_view="http://schemas.android.com/apk/res-auto"

You are missing the prefix for card_view.

This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices.

You could also do

<android.support.v7.widget.CardView
 xmlns:card_view="http://schemas.android.com/apk/res-auto"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.