I have made a XML file:
I've had the same problem too, and there were no problems in Eclipse->Problems for me either.
You might consider adding in a default state for the drawable (as practiced in this ImageButton example at the Android Developers website), shown in this modified version of your presented code:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/calender_h" />
<item
android:state_pressed="false"
android:drawable="@drawable/calender_n" />
<item
android:drawable="@drawable/calender_n" />
</selector>
Otherwise, I would say (from something I've experienced just now in Eclipse) that you should push the app out to your phone or emulator anyway. In Eclipse, I'm staring at a "Failed to parse..." message in my Graphical Layout tab of the layout XML file I am having troubles with, but on my phone, I see the image exactly as it should be (responds perfectly to button presses and whatnot).
In my case, the drawables (PNG files) were corrupted while transferring them from Linux machine to my Windows machine where I do development. I figured that by trying to open the PNG files. Those PNG files could not be opened as they were corrupted.
After transferring them once again, it worked fine.
From Eclipse, right click the xml file and choose Open With -> XML Editor. In this, choose the Design tab. You may notice there is a mysterious child element after your <item>
's which is just empty. Right click on it and choose remove.
Just spent an hour or so trying to fix this problem and this turned out to be the fix, probably some invisible characters that cause parsing to fail. Anyway, hope that helps anyone else having this problem!
4. I`ve also ran into the same problem. What I found is that each of the StateListDrawable states (pressed, selected, focused, etc.) actually expects a valid drawable (png, jpg, gif, etc.). So, that means, something like this will cause the parse error problem:
<item android:state_selected="true" />
I had the same issue and it was due to the name of one of the resource images. The image was sent to me by a designer that introduced some characters not accepted by Android and even when I renamed it inside Eclipse, something "evil" obviously remained. Weird.
You XML is fine. Are you missing the drawables? Try cleaning the project once. If that doesn't help, there might be some invisible special characters in the XML if you have copy-pasted this from somewhere.
Anyway, Look at the problems window. It should give you more details on the error.