有效的 XML 文件给出“无法解析” Android ADT 错误
我已经制作了一个 XML 文件:
<?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" />
</selector>
但它给了我以下错误:
无法解析文件 G:\eclipseHeliosWorkspace\WineCountry\res\drawable\calendar_selector.xml
可能是什么问题?
I have made a XML file:
<?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" />
</selector>
but it is giving me the following error:
Failed to parse file G:\eclipseHeliosWorkspace\WineCountry\res\drawable\calendar_selector.xml
What could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我不确定是否相同,但是
在图书馆项目中更新到 ADT 15 时,我也遇到了类似的问题。
这是目前仍未解决的谷歌问题:21046。
这对我有用:
希望这有帮助!
(如果它仍然相关......)
I'm not sure it's the same, but
Similar issue happened to me when updating to ADT 15, in a library project.
this is the google issue that currently still opened: 21046.
That's what worked for me:
Hope this helps!
(if it's still relevant...)
我也遇到了同样的问题,并且 Eclipse->Problems 对我来说也没有问题。
您可以考虑为可绘制对象添加默认状态(如 ImageButton 示例中所实践的那样< /a> 在 Android 开发人员网站上),如您所提供的代码的修改版本所示:
否则,我会说(根据我刚刚在 Eclipse 中经历过的事情)您应该将应用程序推送到您的手机或模拟器。在 Eclipse 中,我在布局 XML 文件的“图形布局”选项卡中看到“无法解析...”消息,但在我的手机上,我看到的图像与它应该的样子完全一样(响应完美地按下按钮等)。
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:
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).
你的 XML 没问题。您是否缺少绘图?尝试清理该项目一次。如果这没有帮助,那么如果您从某处复制粘贴了 XML,则 XML 中可能存在一些不可见的特殊字符。
不管怎样,看看问题窗口。它应该为您提供有关错误的更多详细信息。
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.
在 Eclipse 中,右键单击 xml 文件并选择“打开方式”->“打开方式”。 XML 编辑器。在此,选择“设计”选项卡。您可能会注意到
之后有一个神秘的子元素,它是空的。右键单击它并选择删除。花了一个小时左右尝试解决这个问题,结果发现这就是解决办法,可能是一些不可见的字符导致解析失败。无论如何,希望能帮助其他遇到这个问题的人!
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.
我也遇到了同样的问题。我发现,每个 StateListDrawable 状态(按下、选择、聚焦等)实际上都需要一个有效的可绘制对象(png、jpg、gif 等)。因此,这意味着类似这样的事情会导致解析错误问题:
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" />
我也遇到了这个。布局 xml 文件和 main.xml 将无法解析。如果您为 main.xml 选择图形视图,您将不会获得任何按钮(在我的例子中)。我发现Eclipse被设置为C++而不是java。将其设置为 java 透视图,关闭然后重新打开 Eclipse 修复了该问题。
现在 Eclipse 正在做其他奇怪的事情,比如间歇性忘记连接到手机。
I also ran into this. The layout xml files and main.xml would not parse. if you chose the graphical view for main.xml you would not get any buttons (in my case). What i found is that Eclipse was set to C++ rather than java. Setting it to the java perspective, closing, then reopening Eclipse fixed the issue.
Now Eclipse is doing other strange stuff like forgetting to connect to the phone intermittently.
我遇到了同样的问题,这是由于资源图像之一的名称造成的。该图像是由一位设计师发送给我的,其中引入了一些 Android 不接受的字符,甚至当我在 Eclipse 中重命名它时,显然仍然存在一些“邪恶”的东西。诡异的。
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.
就我而言,绘图(PNG 文件)在从 Linux 计算机传输到我进行开发的 Windows 计算机时被损坏。我通过尝试打开 PNG 文件发现了这一点。这些 PNG 文件因已损坏而无法打开。
再次转移后,效果很好。
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.