Android Java Coding Errors, Need Assistance - android

I am a beginner coder trying to learn how to make android apps. I am using these tutorials and I guess I have ran into an error.
Here is my text.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="25dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/etCommands"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Type a command"
android:password="true" />
<LinearLayout
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
<Button
android:layout_weight="20"
android:id="#+id/Bresults"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button" />
<ToggleButton
android:layout_weight="80"
android:id="#+id/tbPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:checked="true" />
</LinearLayout>
<TextView
android:id="#+id/tvresults"
android:paddingBottom="10dp"
android:checked="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="invalid" />
</LinearLayout>
I am getting an error next to where it says button. The error says:
Multiple annotations found at this line: - Element type "LinearLayout" must be followed by either attribute specifications, ">" or "/>". - error:error parsing XML:not well-formed (invalid token)"

You need to close the tag on your second Linear Layout >
<LinearLayout
android:weightSum="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"> <!-- here -->

The colorcoding in your post already highlights the issue. You forgot the > after the LinearLayout opening tag.

The IDE is complaining that your xml is not well-formed. If the IDE's errors are not clear enough, you try an online validator such as http://www.xmlvalidation.com/ .

Related

How to reference a layout schema

In Android Studio I have the following layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/entry_entry"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:paddingRight="4dip"
android:textSize="8pt"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dip"
android:layout_weight="0.42"
android:layout_height="wrap_content"
android:gravity="right">
<TextView
android:id="#+id/distance_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="2dip"
android:textSize="8pt"/>
<TextView
android:id="#+id/miles_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="2dip"
android:text="m"
android:textSize="7pt"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/folder_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dip"
android:textSize="6pt"/>
</LinearLayout>
<TextView
android:id="#+id/file_entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="6pt"/>
</LinearLayout>
This layout is copied from an app that worked in Eclipse.
When I "Validate" the xml file I get the following errors:
Error:cvc-elt.1.a: Cannot find the declaration of element
'LinearLayout'.
Error:External resource http://schemas.android.com/apk/res/android is
not registered
Error:Premature end of file.
It seems that the answer will be to register the schema. How do I do that? (I have googled that question but not found an answer.)
There is no XML schema for layout resources. That is because there is an infinite number of element names (based on arbitrary Java classes) and an infinite number of attribute names.
On the whole, I am not aware of an XML schema for any Android resource type. Layouts are the type most resistant to having such a schema, though.

No resource identifier found for attribute 'linearLayoutOrientation' in package 'android'

I was building away with my application and all of the suden i got this error:
No resource identifier found for attribute 'linearLayoutOrientation' in package 'android'
I know where the error is created but i do not know how i can fix this. Can somone take a look and tell me what i am doeing wrong. I am building the application in Xamarin Studio.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffd8d8d8">
<TextView
android:id="#+id/Heading"
android:text="."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0f62ae"
android:textSize="30dp"
android:textColor="#FFFFFFFF"
android:textStyle="bold"
android:padding="15dp" />
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:height="40dp"
android:minHeight="40dp"
android:layout_marginRight="0.0dp"
android:linearLayoutOrientation="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="4.0dp"
android:id="#+id/separator"
android:visibility="visible"
android:background="#ff0b487f" />
<ListView
android:id="#+id/dataListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#ff0f62ae" />
</LinearLayout>
Thanks in advance
remove
android:linearLayoutOrientation="vertical"
from edittext tag
and add
android:orientation="vertical"
in LinearLayout tag
remove android:linearLayoutOrientation="vertical"from editText from layout as you have provided it solve your issue in this context

unfortunately app stop working: Failed to find style 'mapViewStyle' in current theme

I saw so many answer of this question here but not one solve my problem. I am trying to make a tab layout I which there is text is text view in table layout and below table layout I want to add map. and I'm trying to do this but not get the result.
my error is
Failed to find style 'mapViewStylr' in current theme
after adding the MapView I got this error. and when I run the code on Nexus one and try to open the layout in which I added the MapView then the application Unfortunately stopped.
here is my layout code
<?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="wrap_content"
android:orientation="vertical"
android:background="#android:color/white"
>
<ScrollView
android:id="#+id/info_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RelativeLayout
android:id="#+id/venuinfolayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#android:color/white" >
<TableLayout
android:id="#+id/venuetable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true"
android:weightSum="2"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/venueaddress"
android:text="Address:"
android:textColor="#android:color/black"
android:padding="6dip"
android:textStyle="bold"
android:textSize="20dip" />
<TextView
android:id="#+id/venueaddress_details"
android:layout_height="wrap_content"
android:layout_width="180dip"
android:singleLine="false"
android:layout_toRightOf="#id/venueaddress"
android:textColor="#android:color/black"
android:text="text"
android:layout_marginLeft="10dip"
android:padding="6dip"
android:textSize="15dip"
/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="#+id/venuephone"
android:layout_below="#id/venueaddress"
android:text="Phone:"
android:textColor="#android:color/black"
android:padding="6dip"
android:textStyle="bold"
android:textSize="20dip" />
<TextView
android:id="#+id/venuephone_details"
android:layout_below="#id/venueaddress_details"
android:layout_toRightOf="#id/venuephone"
android:text="number"
android:textColor="#android:color/black"
android:layout_marginLeft="10dip"
android:padding="6dip"
android:textSize="15dip" />
</TableRow>
</TableLayout>
<com.google.android.maps.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/venuetable"
android:clickable="true"
android:apiKey="AIzaSyAvWazTUUQr88b_UqQvB4k5rPAtOhlxTFA" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
//try this it may help you
Add this into your manifest file
<uses-library android:name="com.google.android.maps" />
I had the same problem when I try to build a simple app, following the Android MapView tutorial.
The app showed this exception in AVD for the file file main.xml:
Failed to find style 'mapViewStyle' in current theme
At last I found that there is a mistake in file AndroidManifest.xml:
The element should be a child of the element, not immediately within .
Hope this was any help to you.
OR
look Here

Another r cannot be resolved to a variable/error parsing xml junk after document element

I know this is asked a lot but I got error parsing xml junk after document element problem and then after while of looking for the problem I got 10 r can not be defined errors i think it all resulted from the first error. But even when I remove the problem paragraph and click clean the error red x is still there on a blank area.The error started on the textview line at the bottom.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="25dp" >
<EditText
android:id="#+id/etCommands"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Type a Command"
android:password="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:id="#+id/bResults"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
android:text="Try Command" />
<ToggleButton
android:id="#+id/tbPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="80"
android:checked="true"
android:paddingBottom="10dp"
android:text="ToggleButton" />
</LinearLayout>
<TextView
android:text="invalid"
android:id="#+id/tvResults"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" />
should be
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >
Notice no / at the end of the tag. The / at the end is xml for "close this tag right now please." As it stands, you have invalid xml with two open tags for LinearLayout but closing LinearLayout 3 times.
It's hard to know what is the problem when you don't provide the full xml file. You probably forgot to close one of your LinearLayout items.
edit:
simply delete the / character from your LinearLayout declaration:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100" >

Receiving error on project build - "Error parsing XML: unbound prefix"

I am new to Android Development and trying to create a sample application. Can anyone tell me whats wrong with following layout (activity_sample.xml)? -
<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="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/app_name"
tools:context=".SampleActivity" />
</LinearLayout>
On Build, I am getting following error -
error: Error parsing XML: unbound prefix activity_sample.xml /Sample/res/layout line 4 Android AAPT Problem
You haven't declared the tools prefix in your XML. Try using:
<LinearLayout 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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/app_name"
tools:context=".SampleActivity" />
</LinearLayout>

Categories

Resources