Android / Eclipse / Premature end of xml file

Let me start by acknowledging that I did find a similar question on here but there was only one answer and that answer did not apply in my situation, so…

I am just now wading into Android and have come upon a sticking point. I am using Eclipse and have run into a problem trying to create a state-list drawable and keep getting a “premature end of file” error in Eclipse. I have the images in my “drawable” directory. I create a new file, name it date.xml, and type the following:

  • Android Bottom Navigation Bar with drop shadow
  • Where can I download the Android SDK Documentation?
  • Displaying SVG files in Android
  • Scrollview not scrolling down completely
  • Facebook SDK + SlidingMenu SDK = Jar mismatch! Fix your dependencies
  • Connect to password protected wifi network using adb shell
  • <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/dategrey" android:state_selected="true" />
        <item android:drawable="@drawable/datewhite" />
    </selector>
    

    The exact error that I am getting is “Premature end of file. Error parsing XML: No elements found.”. The has me confused as there is clearly an element in there. What am I missing?

    Related posts:

    Android imageview change tint to simulate button click
    Using layout_above in a RelativeLayout
    admob ads are not shown with pro guard
    How to center items of a recyclerview?
    Android - Custom Dialog - Can&#039;t get text from EditText
    Keep activity always on top of stack, or in focus when rogue apps launch activities?
  • How to run the new Chrome for Android 4 on Android Emulator?
  • Get list of dependencies runtime
  • Handling SQLite tables and cursors on Android
  • How to convert a color integer to a hex String in Android?
  • Compile and use ABI-dependent executable binaries in Android with Android Studio 2.2 and CMake
  • setvisibility(view.visible) not working after setvisibility(view.gone)
  • 9 Solutions collect form web for “Android / Eclipse / Premature end of xml file”

    And I solved it. Man, what a goofy thing to have confound me for two days! I cleaned the project, rebuilt the xml file, and it works fine. I have no idea what was plugging things up as I had never actually tried to run the project so there should not have been an issue with out.out, but it worked. Thanks to all who offered advice. I truly do appreciate your time and attention in helping me with this one.

    You might look at this answer.

    That person’s problem was that the file was not created as an XML file, from Eclipse’s point of view. Try File > New > Other… / select XML.

    Try

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true"
            android:drawable="@drawable/dategrey" />
        <item android:drawable="@drawable/datewhite" />
    </selector>
    

    You need to check the state first then call the specific drawable.

    I had the same issue. Confusing, but it was an out xml file causing the issue. The name was similar so i did not notice it was actually a completely different file game_layout_out.xml.
    Delete the out file and youre fine.

    i got the same error using PhoneGap.

    New >> Project >> Android Project from Existing Code

    Then Next and Browse project and LEAVE BLANK copy projects into workspace and Finish.

    There you go !!

    You need to keep the new xml file in res/layout folder….and done…
    thanks

    I just removed this line

    <?xml version="1.0" encoding="utf-8"?>
    

    Saved, built, then re-added it again and it was fine

    This is what I did: I added a new line at the end the file, saved the XML file, and then removed that recently added line.

    That trivial operation solved my problem with the XML file.

    Is http://schemas.android.com/apk/res/android alive?

    The XML editor will try to download the XML Schema to validate the XML. If the site is down or the XML schema is damaged, this could cause these errors.

    Try to download the schema and add it to your “xml catalogue” (search in your Eclipse preferences) to avoid this problem.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.