Here is the snippet of main.xml.Although android:layout_width is used its giving attribute is missing.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="#+id/eventlabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:layout_weight="1"
android:paddingBottom="10px"/>
</LinearLayout>
Could someone point out the mistake?Thanks
You have:
<LinearLayout xmlns="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools
Change it to:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<!-- rest is the same -->
You only had xmlns=... and didn't actually specify the android part of it. Also, your tools XMLNS was missing a closing "
Try cleaning your solution and then build it again.
Related
I'm having a trouble using the <include> element in my layout files. The exact error is:
[databinding] {"msg":"\u003cinclude id\u003d\u0027#+id/displayArea\u0027\u003e conflicts with an ID used by a view in this layout","file":"badlayout/res/layout-land/main.xml","pos":[{"line0":10,"col0":2,"line1":20,"col1":16}]}
[databinding] {"msg":"\u003cinclude id\u003d\u0027#+id/displayArea\u0027\u003e conflicts with an ID used by a view in this layout","file":"badlayout/res/layout-port/main.xml","pos":[{"line0":10,"col0":2,"line1":10,"col1":67}]}
The problem happens when I set android:id in an <include> element in layout-port/main.xml:
<include android:id="#+id/displayArea" layout="#layout/display" />
while using the same ID directly in layout-land/main.xml:
<LinearLayout android:id="#+id/displayArea"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
...
</LinearLayout>
Experimenting shows I can't mix-n-match these. I can either specify android:id in the <include> tags, or in ordinary views, but not both.
Can anybody explain exactly what this message means, and what the rules are?
This is all complicated by the fact that you also can't set android:id at the top level of a layout file without running into different problems.
This is an older app. These layout files never gave me any trouble in Eclipse; I only started getting the errors after moving to Android Studio.
For completeness, the complete xml files are shown here:
layout-land/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:id="#+id/displayArea"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false">
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
layout-port/main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<include android:id="#+id/displayArea" layout="#layout/display" />
</LinearLayout>
layout/display.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView android:id="#+id/StatusLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
I have an error "Unexpected namespace prefix "xmlns" found for tag LinearLayout" in "xmlns:android="http://schemas.android.com/apk/res/android" in LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:background="#drawable/wallpaper"
android:layout_height="match_parent" >
<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:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
There is no need for placing namespace attribute for every Layout you defined in you layout.xml files. Namespace can be defined for a root level element only as below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:background="#drawable/wallpaper"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
Remove this line
xmlns:android="http://schemas.android.com/apk/res/android"
from your LinearLayout. You only add that once, in your root layout. You can only define a namespace once in each xml
The XML appears to be well-formed. You can perhaps circumvent the problems by changing the XML, but that doesn't explain why you are getting the error. I think we need to know more about how you are parsing the XML. Check whether other XML parsers accept it.
I'm trying to fix this so badly but I couldn't find where I've gone wrong.
The message:
Element type "LinearLayout" must be followed by either attribute specifications, ">" or "/>".
Why do I get this? Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
**<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="70"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#0000FF"
android:padding="20dp"
android:paddingBottom="10dp"
android:gravity="center_horizontal">
</LinearLayout>
</LinearLayout>
It's a pretty self-explanatory error message.
You didn't close your LinearLayout tag. Add a > after android:orientation="vertical".
You missed a ">" at the end:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
Your first LinearLayout tag isn't closed. Add a > to the end of it, like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
^
Error clearly states that you missed the closing tag. Every Layout and its attribute needs to have their own opening and closing tag. Add
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="70"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
or
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_weight="70"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
I'm brand new to eclipse and programming and I'm following video tutorials but I can't figure out why my eclipse doesn't recognizing the coding. In the video I see that he adds
android:gravity=center
android:background="#color/red"
and it changes color but mine does not..
the android:gravity changes to a pink color and the =... changes to blue but mine stays black and when I look at the graphic layout the code is not registering
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
android:gravity=center
android:background="#color/red"
<TextView
android:layout_height="wrap_content"
android:text="#string/red" android:layout_width="wrap_content"/>
</LinearLayout>
Here is the corrected Code,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#ff0000"
>
<TextView
android:layout_height="wrap_content"
android:text="#string/red"
android:layout_width="wrap_content"
/>
</LinearLayout>
Color can be also defined in XML files.
Create a new xml file name color.xml inside /res/values.
Paste the following code inside
<color name="red">#FF0000</color>
Also Make sure you have the following line in strings.xml
<string name="red">Your text</string>
and change the code as follows.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#color/red"
>
<TextView
android:layout_height="wrap_content"
android:text="#string/red"
android:layout_width="wrap_content"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
-----------------
android:gravity=center
android:background="#color/red"
-----------------
That bit is wrong. It has be declared inside the layout object. Remove it.
<TextView
android:layout_height="wrap_content"
android:text="#string/red" android:layout_width="wrap_content"/>
</LinearLayout>
Have you declared the color red in your resource folder under string xml file?
Read
Missing the quotes in android:gravity="center"
You need to create a color resource: <color name="red">#FF0000</color>
You can find the documentation for the color resource here: http://developer.android.com/guide/topics/resources/more-resources.html
I am getting an "Error parsing XML file: Unbound prefix" when I try to put my AdMob ad reference above a tabbed view. Any ideas how to fix that?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp">
<com.admob.android.ads.AdView android:id="#+id/ad"
android:layout_width="fill_parent" android:layout_height="wrap_content"
myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
You're using this:
myapp:backgroundColor
but I don't see any declaration of the 'myapp' prefix. so that might be the source of the error.
Just like the "android" namespace is declared in the xml like this:
xmlns:android="http://schemas.android.com/apk/res/android"
the 'myapp' namespace should have a declaration somewhere also
This answer seems related.
You need both the xmlns set correctly, as Nanne said, as well as your attributes defined in res/style/attrs.xml.
The xmlns appears to be:
xmlns:admob="http://schemas.android.com/apk/res/com.example.package"
For an example attrs.xml, check out the answer above.