Reputation: 11
I am new to java programming and am strictly following one tutorial right now. I got pretty far into it until something happened that I just can't fix. I searched google and looked at the code over and over and did not see anything wrong. Here's a screenshot of my code....nvm I am not allowed to post pictures because I'm new so here is the code copied. The first X says Error parsing XML: not well formed(invalid token) and the second X says XML document structures must start and end within the same entity. I appreciate all the help, thanks.
< ?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" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myMessage"
android:text="@string/hello" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myButton"
android:text="@string/answer"
/>
< LinearLayout--------1st X is located here. The < is not spaced in the code but spaced here because that was the only way i could put it here
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#ff0000"
android:textColor="#000000"
android:text="red" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#00ff00"
android:textColor="#000000"
android:text="green" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#0000ff"
android:textColor="#000000"
android:text="blue" />
< LinearLayout >---------2nd X is located here. The < is not spaced in the code but spaced here because that was the only way i could put it here and there is a / in between < and LinearLayout
Upvotes: 1
Views: 8447
Reputation: 132982
remove spaces from <LinearLayout
tags .use <LinearLayout
instead of < LinearLayou
as
<?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" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myMessage"
android:text="@string/hello" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myButton"
android:text="@string/answer"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#ff0000"
android:textColor="#000000"
android:text="red" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#00ff00"
android:textColor="#000000"
android:text="green" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#0000ff"
android:textColor="#000000"
android:text="blue" />
</LinearLayout>
</LinearLayout>
Upvotes: 0
Reputation: 1717
You cannot allow to give space between open tag and tag name. Give linear layout tag without space like
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" >
This is wrong
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
Upvotes: 0
Reputation: 7532
You miss one close tag </LinearLayout>
at bottom. Here the working one `
<TextView
android:id="@+id/myMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/answer" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ff0000"
android:gravity="center"
android:text="red"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#00ff00"
android:gravity="center"
android:text="green"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#0000ff"
android:gravity="center"
android:text="blue"
android:textColor="#000000" />
</LinearLayout>
`
Upvotes: 0
Reputation: 11
xml is not structured well... below is the corrected one. there should not be a space between < LinearLayout & this tag is not closed properly.
<?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">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myMessage"
android:text="@string/hello" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myButton"
android:text="@string/answer"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#ff0000"
android:textColor="#000000"
android:text="red" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#00ff00"
android:textColor="#000000"
android:text="green" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:background="#0000ff"
android:textColor="#000000"
android:text="blue" />
</LinearLayout >
</LinearLayout >
Upvotes: 1