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

<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.

Related

Android Studio does not show layoutpreview

I am trying to create a layout in Android Studio but the preview of the layout is not showing at all. There is no errour though.
How can i get it to work properly? I will add a screenshot.
Preview not loading the layout
Thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="#+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.diceout.MainActivity"
tools:showIn="#layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Let's Play!" />
<Button
android:id="#+id/rollButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="155dp"
android:layout_marginStart="155dp"
android:layout_marginTop="25dp"
android:text="Roll" />
</RelativeLayout>
TextView
#ivan franken Could you post your #layout/activity_main Xml code. I saw this line tools:showIn:#layout/activity_main
in code on your content_main.xml. I tested it in my project and got similiar result to yours. But when I deleted it, it worked fine.

Android, Background not keeping proportions while writing in TextEditor

I've got a problem with a background while writing in EditText on my phone.
My background is changing size, and not keeping right proportions.
I would like it to be hidden behind keyboard.
This is my full 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:background="#drawable/tlo4">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_add_advice"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.jagoda.myapplication.AddAdvice">
<TextView
android:id="#+id/tytul_add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style = "#style/tekst"
android:text=""/>
<TextView
android:id="#+id/tytul2_add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tytul_add"
style = "#style/tytulDuzy"
android:text=""/>
<EditText
android:id="#+id/new_ad"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginTop="20dp"
android:layout_below="#id/tytul2_add"
style="#style/tekst2" />
<Button
style="#style/przycisk"
android:text="Dodaj rozwiązanie"
android:layout_width="340dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_below="#id/new_ad"
android:onClick="to_home"
android:id="#+id/button"/>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Before writing in EditText:
While writing in EditText:
in AndroidManifest try to add to your activity's body this: android:windowSoftInputMode="adjustPan"

Android: "Error parsing XML: must not undeclare prefix"

I am very new to android development and was in the process of trying to create my first process when I came across the build error with which the question is titled.
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app= ""
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.austinc.clicker.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="#+id/textViewCount"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="24dp" />
<Button
android:text="Reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ButtonClick"
android:layout_alignLeft="#+id/ButtonClick"
android:layout_alignStart="#+id/ButtonClick"
android:layout_marginTop="61dp"
android:id="#+id/buttonReset" />
<Button
android:text="Click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="55dp"
android:id="#+id/ButtonClick"
android:layout_below="#+id/textViewCount"
android:layout_centerHorizontal="true" />
</RelativeLayout>
From what I can infer by double clicking on the error, the problem has to do with the second line of code (the meaning of which I have no idea). Is this a quick fix, or have I made a mistake somewhere in editing some piece of code?
I also faced the same issue, searched for 15 minutes and found the solution, i modified first three lines in content_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.user.demoapp.MainActivity"
tools:showIn="#layout/activity_main">

Multiple annotations found at this line

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.

Android: <include/> layout crashes application on landscape

I tried to use the include tag to reuse the layout code from the activity_main.xml and contact_details.xml during landscape mode. I would like to display the activity_main on the left and contact_details on the right. But the application crashes when I switch to landscape mode.
This is the coding for the activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button
android:id="#+id/btnAddContact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="0"
android:text="Add Contact" />
</LinearLayout>
This is the coding for contact_details.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/lvContactDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
This is the coding for my layout-land/activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<include layout="#layout/activity_main"/>
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#A3A3A3"/>
<include layout="#layout/contact_details"/>
</LinearLayout>
Any tips for resolving this problem? Thanks in advance.
Thanks Adinia for the suggestion. It was because I should not call back the same Layout name, which is activity_main.xml. This is the main cause of the crash. it might be a circular reference as Adinia had stated. Thanks again. By the way, I am only allowed to accept my answer in 2 days.
In your activity_main.xml ,contact_details.xml you are using
android:layout_width="fill_parent"
instead that try using
android:layout_width="wrap_content"
If not post you logcat report

Categories

Resources