Gradle: Error parsing XML: not well-formed (invalid token) - android

I'm getting this compilation error in my XML file but I cant seem to spot the problem.. The error actually randomly came and I don't recall even touching this file but maybe I just cant see the problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MyBetsWindow">
<Button
android:id="#+id/AddBetButton"
android:text="Add Bet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="#+id/BetListLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>

By me, your code works ; the error doesn't come from your layout.
Here is what it's doing on a old program that I made called ABar:
So check something else !

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: "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">

Relative Layout buttons are not visible

Anyone please help me figure out why is the following button1 is not visible in my application?
<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: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=".AirplaneActivity" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/button_activate"
android:onClick="activateAirPlaneMode"/>
</RelativeLayout>
Did you call setContentView(R.layout.layout_name);, where layout_name is the name of your xml file in layouts (assuming it's an Activity)?
There doesn't seem to be anything wrong with your XML file so it must be something else.
If you provide more context/code, it may be more helpful.

Error parsing XML: unbound prefix

I'm new to android and trying to learn some basic stuff, My problem is if i paste this line android:layout_gravity="center" in the default "activity_main.xml" file I'm getting the error in the title but if I delete the line the error disappears!
<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: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.helloworld.MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:textSize="70dp"
android:layout_height="wrap_content"
andriod:layout_gravity="center"
android:text="#string/hello_world"
/>
</RelativeLayout>
I appreciate any help
Your error is simple
Instead of
andriod:layout_gravity
write
android:layout_gravity

AutoCompleteTextView does not appear above listview

Well I ve been trying this all day but I could not find the error , and I am in a deadend. I have a xml file which I have a listview and of my list I want to have a AutoCompleteTextView which I will use as search bar later.The problem is that in my xml file everything seems to be fine and appears both listview and AutoCompleteTextView but when i run my app in the emulator prints only the list view. I ve tried to use editText instead of autocoplete but again nothing happened. here is my xml 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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
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=".sqlviewpatients" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:ems="10"
android:text="AutoCompleteTextView" />
</RelativeLayout>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout1" >
</ListView>
</RelativeLayout>
Please tell me what I am doing wrong? I don t know what else can I do
Ok I found the error!!! in the .java file I had my class extend List Activity and I had in comment the setContentView(R.layout.something) that was the error, the setContent should not be a comment!It took me 2 days of to found it so I hope this answer will be helpful to others

Categories

Resources