{"id":55,"date":"2012-02-29T04:30:09","date_gmt":"2012-02-29T09:30:09","guid":{"rendered":"https:\/\/www.falatic.com\/?p=55"},"modified":"2012-02-29T04:31:04","modified_gmt":"2012-02-29T09:31:04","slug":"android-eclipse-xml-files-and-weird-error-messages","status":"publish","type":"post","link":"https:\/\/www.falatic.com\/index.php\/55\/android-eclipse-xml-files-and-weird-error-messages","title":{"rendered":"Android, Eclipse, XML files and weird error messages"},"content":{"rendered":"<p>More than once, I&#8217;ve gotten the following weird problem when looking at an XML layout for Android in Eclipse:<\/p>\n<blockquote><p>Failed to parse file C:\\Eclipse_workspace\\ButtonTest2\\res\\drawable\\arrow_1.xml<br \/>\nException details are logged in Window &gt; Show View &gt; Error Log<\/p><\/blockquote>\n<p>The error itself isn&#8217;t exactly informative, and certainly doesn&#8217;t make sense:<\/p>\n<blockquote><p>org.xmlpull.v1.XmlPullParserException: PI must not start with xml (position:unknown @1:5 in java.io.InputStreamReader@1c167686)<br \/>\nat org.kxml2.io.KXmlParser.exception(Unknown Source)<br \/>\n&#8230;&#8230;.<\/p><\/blockquote>\n<p>Hmm. XML files should start with an appropriate declaration line, yet this says my XML file shouldn&#8217;t have it. <a href=\"http:\/\/media.tumblr.com\/tumblr_lv3b95UzuK1r2xg26.jpg\" target=\"_blank\">That&#8217;s&#8230; weird.<\/a> Normally I just remove the line til it stops complaining but as I&#8217;m playing with the second pre-release of r17 android SDK (some key components have been broken lately) and feeling bold I decided to understand this once and for all. What follows is the text of my answer <a href=\"http:\/\/stackoverflow.com\/a\/9496265\/760905\">on StackOverflow<\/a> earlier tonight:<\/p>\n<hr \/>\n<p>I&#8217;ve beaten my head against this wall a few times and now I have the answer (I *hate* mysterious behavior, especially when it seems to be random).<\/p>\n<p>I just ran a 4-way test (Unix and DOS, with and without the binary &#8220;EF BB BF&#8221; BOM header\/signature). <strong>I found that Eclipse does not put a binary BOM header into XML files it creates, period.<\/strong> If you add a file that has the `&#8221;&lt;?xml &#8230; ?&gt;&#8221;` declaration header, it works correctly ONLY if that binary signature is ABSENT. (Whether EOLs are Unix or DOS doesn&#8217;t matter). If you have *both* forms of header you get this problem. You can have one, the other, or neither, but never both.<\/p>\n<p>So, if you create a new XML file in Eclipse you can expect (in 3.6 &#8211; 3.7.1 anyway) that it has no binary BOM header and you should properly put a `&#8221;&lt;?xml &#8230; ?&gt;&#8221;` declaration header in there to identify it as Unicode. If you IMPORT a project that has files with binary BOM header signatures or use an external editor that likes to add them, that&#8217;s where all this fun begins.<\/p>\n<p><strong>Ideally, ensure XML files with declaration don&#8217;t have binary BOM header before importing them&#8230; otherwise, remove that `&#8221;&lt;?xml &#8230; ?&gt;&#8221;` declaration header whenever Eclipse complains&#8230; short of removing the binary header that&#8217;s all you can readily do.<\/strong> (It&#8217;d be nice if Eclipse handled this more consistently&#8230; or at least gave you a way to identify and fix the problem readily by removing the binary BOM header&#8230;)<\/p>\n<p>*\u00a0<em>If in doubt, examine the file with an external hex editor, preferably one that is NOT Unicode-aware (<a href=\"http:\/\/www.x-ways.net\/winhex\/\" target=\"_blank\">WinHex<\/a> worked for me, YMMV). Some text\/hex editors will auto-detect Unicode and may auto-add a header when the file didn&#8217;t really have one.<\/em><\/p>\n<hr \/>\n<p>Postscript: I use <a href=\"http:\/\/www.ultraedit.com\/\" target=\"_blank\">IDM&#8217;s UltraEdit \/ UltraCompare<\/a> primarily. They work great but they&#8217;re a little <em>too<\/em> good at determining if a file is Unicode or not, to the point where these four text files ALL had the binary BOM header in hex mode!! <a href=\"http:\/\/www.x-ways.net\/winhex\/\" target=\"_blank\">WinHex<\/a> showed the exact situation, and indeed only two of the files actually had that header. However, I&#8217;d like my regular editor to work correctly. Time to write IDM an email&#8230;<\/p>\n<!-- wpsso rrssb get buttons: buttons on archive option not enabled -->\n","protected":false},"excerpt":{"rendered":"<p>More than once, I&#8217;ve gotten the following weird problem when looking at an XML layout for Android in Eclipse: Failed to parse file C:\\Eclipse_workspace\\ButtonTest2\\res\\drawable\\arrow_1.xml Exception details are logged in Window <a href=\"https:\/\/www.falatic.com\/index.php\/55\/android-eclipse-xml-files-and-weird-error-messages\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[1],"tags":[],"class_list":["entry","author-marty","post-55","post","type-post","status-publish","format-standard","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/comments?post=55"}],"version-history":[{"count":0,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/posts\/55\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/media?parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/categories?post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.falatic.com\/index.php\/wp-json\/wp\/v2\/tags?post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}