Apparently I have duplicate attributes but cannot spot this, I have gone through the XML line by line but cannot see what's wrong. I have tried to clean, build and have also closed eclipse and opened it again. Also this is a new xml file I created in layout as I wanted to change the text displayed within listview instead of using the standard one
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
android:layout_height="0dp"
android:layout_width ="fill_parent"
android:textSize="20sp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:gravity="center">
</TextView>
Here is a screenshot of where the error is pointing to
SCREENSHOT
ok, it is just an assumption, but the id "text1" is used by android System listview to refer to the internal build textview. Just use another id like
android:id="#+id/my_textview_1"
I guess problem is this line: android:id="#android:id/text1"
change it with this android:id="#+id/text1"
Related
This is driving me mad. My project compiled fine a moment ago. I made some minor change somewhere else, and now I'm getting this error. Here's the error message in full:
no resource found that matches the given name (at 'layout_above' with value '#id/blank_view").
Here's my XML file where the error is occurring:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/margin_right"
android:layout_above="#id/blank_view"
android:src="#drawable/button" />
<View
android:id="#+id/blank_view"
android:layout_width="match_parent"
android:layout_height="#dimen/margin_bottom"
android:layout_alignParentBottom="true" />
</RelativeLayout>
How in the hell could it be failing to find a resource with the name "#id/blank_view" when that resource is just below it in the file?
Btw, the reason I have my layout like this is that I want the ImageButton to be aligned to the bottom of my relative layout, but offset up by a margin. For some reason, those two attributes (layout_alignParentBottom and layout_marginBottom) don't mix well in the same view.
I should also point out that this happened earlier as well, but I just removed the reference that was giving AndroidStudio such a problem, rather than trying to fix it. This, however, is too important to wave away like that.
This happens because the xml is parsed in a linear fashion and the views/objects created in a top to bottom order. So your xml tells the view builder to put your ImageButton above an item that does not exist yet.
Just move it below the blank view and the error should go away.
Try to add the property to your view:
<view
android:id="#+id/blank_view"
android:layout_width="match_parent"
android:layout_height="#dimen/margin_bottom"
android:layout_alignParentBottom="true"
android:layout_below="#id/btn"
/>
And remove:
android:layout_above="#id/blank_view"
Good evening, I am new to studying Java and XML for mobile applications and have a quick question for you guys.
I am trying to edit an XML file here and the error "The markup in the document following the root must be well-formed" appears on one of the lines (The last one)
So I opt to delete the last line from the code but whenever I delete it, it just reappears and prevents me from compiling the program. Can anyone help by answering why this is happening? Your help would be very much appreciated.
<?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" >
<Button
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=""/>
</LinearLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android"></menu> <----- (this is the line that keeps coming back after being deleted)
Delete the xml file and recreate it from scratch.
Try crtl+shift+F to format document.
Hope it will help.
I am creating a button in my XML and here is the creation parameters
<Button android:id="#+id/btn2"
---> android:layout_width="wrap_content" <----
android:layout_height="wrap_content"
android:text="#string/PNR"
/>
I am getting and error in the line indicated saying :
" Element type "Button" must be followed by either attribute specifications, ">" or "/>" "
Not only in button id I try to create TextView or so then also same error comes and at same place.
I have checked earlier posts but they said that the tags were not closed and did not worked for me.
Please suggest me, what to do? Here is the full code :
<?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" >
<Button android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/PNR"
/>
</LinearLayout>
Try cleaning your project
Project --> Clean... then choose your project
Sometimes Eclipse doesn't pick up changes to your xml. When you get goofy errors like this always try cleaning first. Sometimes you will get ClassCastException in Java code when running right after changing something in xml like
cannot cast Button to EditText
or something similar that won't make sense. This is also a good time to clean your project.
I would also recommend getting rid of whitespace within elements because I have had trouble with that as well (especially on older versions of Eclipse) plus I think it looks cleaner. So I would change your <Button... to
<Button android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/PNR"/> <!-- just moved your end tag to this line -->
I'm building my first Android program from a book. It kept crashing on an XML file. I downloaded the xml code from the book, used it and it ran fine!
When I look at them, they both look the same to me! Am I missing something about XML - are there funny empty space problems, capitals, special characters or has my XML just got an odd gremlin in it!
It's working now, but I'd like to know why.
This works!
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip">
<TextView
android:id="#+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/about_text" />
</ScrollView>
This doesn't work: crashes with: java.lang.runtime.exception. Binary xml file lin #1: You must supply layout_width attribute.
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android.layout_width="fill_parent"
android.layout_height="fill_parent"
android:padding="10dip">
<TextView
android:id="#+id/about_content"
android.width ="wrap_content"
android.height ="wrap_content"
android:text="#string/about_text"/>
</ScrollView>
In the XML that does not work, you've got periods (.) in the attribute names:
android.layout_width
and
android.layout_height
which need to use colons (:) instead:
android:layout_width
and
android:layout_height
for future reference their are tools that you can use to help you spot differences between supposedly identical files. Liquid XML Editor is one such tool but there are many more including one from Microsoft, the feature is imaginatively called xml diff ie xml difference.
Let me first explain what my Androïd application is made of :
- a class extended from an Activity. In the OnCreate member of my class, I try to access a TextView described in my main.xml file by using
"MyTextView=(TextView)findViewById(R.id.myTextView);".
- an xml file where the TextView is described as follows :
<TextView
android:name="#+id/myTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/another TextView"/>
In the R.java file, I can see that my TextView is registered.
My problem is that, when I try to get a handle on the TextView with the findViewById function, I get a null pointer.
It seems a mystery to me because I wrote another application where I was able to access TextViews. And I can't see any difference beetween both applications!!!
Hello,
Here is my complete layout file :
<TextView
android:name="#+id/Titre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Application GPS :"/>
<TextView
android:name="#+id/NombreMaxSatellites"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:name="#+id/NombreSatellites"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello Android from NetBeans"/>
<TextView
android:name="#+id/TempsAcquisition"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello Android from NetBeans"/>
<EditText
android:name="#+id/Texte"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Le texte"/>
<Button android:id="#+id/BoutonTexte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dip"
android:layout_marginTop="10dip"
android:text="Terminer"/>
I can access the Button but neither the TextView nor the EditText.
Any idea?
I am sure there are some errors in the layout, due to which your changes for layout were not saved. And then it is not reflecting in R.Java. Look for any red marks in your layout. Resolve the errors before your proceed, then it should work fine. Post your complete layout file.
Make sure that any calls to findViewById() occur after setting the layout with setContentView().
A good practice is to call setContentView() as the first line in your onCreate() method.
Make sure about 2 things
the ID of your textview is not repeated in the same layout
make sure that you are setting the content view (setContentView()) to the correct layout.
The problem is id is assigned to name android:name="#+id/Titre", it should be android:id="#+id/Titre".