Multiple annotations found at this line - android

Multiple annotations found at this line: - error: Error parsing XML: junk after document element The markup in the document following the root element must be well-formed.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.onyourcar.MainActivity"
tools:ignore="MergeRootFrame" />
<TextView
android:id="#+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world"
tools:context=".MainActivity" />

A default texview is like so
<TextView
android:id="#+id/theTextViewIdHere"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
And try to use a relative/linear layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" >
<TextView
android:id="#+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/hello_world" />
</RelativeLayout>
If you would like to use FrameLayout hit google for example code
My first guess at your problem was the last line of 'tools:context' try removing that line. In case this does not work post your entire XML file.
Hope this will help.

Related

Facing issue while creating wear App XML : AAPT: error: attribute android:boxedEdges not found

In the below XML, I am getting error over android:boxedEdges="all". I have tried to remove this line but not solved it.
I am still getting the AAPT: error: attribute android:boxedEdges not found
<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="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:background="#color/dark_grey"
android:padding="#dimen/box_inset_layout_padding"
tools:context=".MainActivity"
tools:deviceIds="wear">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/inner_frame_layout_padding"
android:boxedEdges="all">
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/hello_world" />
<Button
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:text="Press Here" />
</FrameLayout>
</androidx.wear.widget.BoxInsetLayout>
This is a simple wear OS project. I am new on that so any help or link will appreciates.
It is app:boxedEdges, not android:boxedEdges as per the BoxInsetLayout documentation.

Android Studio XML context error

Hi I'm following this Simple Parse Messaging App tutorial-https://github.com/codepath/android_guides/wiki/Building-Simple-Chat-Client-with-Parse
And I'm getting an error on this line of code:
tools:context="${relativePackage}.${activityClass}"
This is the whole file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context="${relativePackage}.${activityClass}" >
<EditText
android:id="#+id/etMessage"
android:layout_toLeftOf="#+id/btSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btSend"
android:gravity="top"
android:hint="contribute..."
android:imeOptions="actionSend"/>
<Button
android:id="#+id/btSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|right"
android:paddingRight="10dp"
android:layout_alignParentRight="true"
android:text="send"
android:textSize="18sp" >
</Button>
</RelativeLayout>
Replace ${relativePackage} with your package name and replace ${activityClass} with your class name.
For example:
tools:context="whatever.your.package.name.ChatActivity"
I think the tutorial means you should populate relativePackage and activityClass yourself. tools:context must refer to a specific Activity, e.g. com.example.MainActivity.

XML documents must start and end within the same entity help me

<RelativeLayout 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"
tools:context="${packageName}.${activityClass}" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
tools:context=".MainActivity" >
<AnalogClock
android:id="#+id/analogClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="290dp" />
<TextClock
android:id="#+id/textClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="146dp"
android:text="#+id/textclock"
android:textColor="#FFFFFF"
android:textSize="100sp" />
</RelativeLayout>
Can I have some help on this I'm really confused would really appreciate some advice. I was just cleaning up my code when this error appeared. I have no idea on how to fix
The error comes because you didn't close RelativeLayout tag in your xml file,so add </RelativeLayout>at the end of xml file.
You don't need to add two relative layout where one parent layout is useless
So simply replace in your code
<RelativeLayout 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"
tools:context="${packageName}.${activityClass}" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
tools:context=".MainActivity" >
with
<RelativeLayout 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:background="#drawable/bg"
tools:context=".MainActivity" >
Second Option is
Remove your xml code and saved the xml file. After that,replace it with the above code and save. The error will be gone. It is probably a remnant from the time when "automatically build project" enabled.

New to XML Coding and receiving this error. error: Error parsing XML: junk after document element

error: Error parsing XML: junk after document element
I'm doing a VERY BASIC CODE JUST FROM NOTHING TO GET BETTER.
<?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="vertical">
<textview
android:layout_width="1dp"
android:layout_weight="0dp"
android:layout_height="175dp"
android:text="#string/welcome_app"
android:text="#string/action_settings" ></textview>
</LinearLayout>
You are not allowed to have spaces at the end of the TextView tag.
Remove the " " at the end of the tag.
Replace <textview> with <TextView>
This should work:
<TextView
android:layout_width="1dp"
android:layout_height="175dp"
android:text="#string/action_settings"/>
// I Modify your code now try it.
<?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="vertical" >
<TextView
android:layout_width="1dp"
android:layout_height="175dp"
android:text="#string/welcome_app" >
</TextView>
</LinearLayout>
The tags are case-sensitive, so use:
<Textview
android:layout_width="1dp"
android:layout_weight="0dp"
android:layout_height="175dp"
android:text="#string/welcome_app"
android:text="#string/action_settings" >
</Textview>

How to include layout inside layout?

How to include layout inside layout in Android?
I am creating common layout. I want to include that layout in another page.
Edit: As in a comment rightly requested here some more information. Use the include tag
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/yourlayout" />
to include the layout you want to reuse.
Check this link out...
Note that if you include android:id... into the <include /> tag, it will override whatever id was defined inside the included layout. For example:
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/some_id_if_needed"
layout="#layout/yourlayout" />
yourlayout.xml:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/some_other_id">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/button1" />
</LinearLayout>
Then you would reference this included layout in code as follows:
View includedLayout = findViewById(R.id.some_id_if_needed);
Button insideTheIncludedLayout = (Button)includedLayout.findViewById(R.id.button1);
Use <include /> tag.
<include
android:id="#+id/some_id_if_needed"
layout="#layout/some_layout"/>
Also, read Creating Reusable UI Components and Merging Layouts articles.
Try this
<include
android:id="#+id/OnlineOffline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
layout="#layout/YourLayoutName" />
From Official documents about Re-using Layouts
Although Android offers a variety of widgets to provide small and
re-usable interactive elements, you might also need to re-use larger
components that require a special layout. To efficiently re-use
complete layouts, you can use the tag to embed another
layout inside the current layout.
Here is my header.xml file which i can reuse using include tag
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="#string/app_name"
android:textColor="#000000" />
</RelativeLayout>
No I use the tag in XML to add another layout from another XML file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#f0f0f0" >
<include
android:id="#+id/header_VIEW"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/header" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dp" >
</LinearLayout>
Learn More Using this link
https://developer.android.com/training/improving-layouts/reusing-layouts.html
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Game_logic">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:id="#+id/text1"
android:textStyle="bold"
tools:text="Player " />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginLeft="20dp"
android:id="#+id/text2"
tools:text="Player 2" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Blockquote
Above layout you can used in other activity using
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SinglePlayer">
<include layout="#layout/activity_game_logic"/>
</androidx.constraintlayout.widget.ConstraintLayout>

Categories

Resources