Android XML 查看器失败
我遇到这个问题已经有一段时间了:
这是我的 header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/logo_text"/>
</LinearLayout>
这是 Eclipse/Android XML 查看器给我的:
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
这种情况也发生在其他项目中以及看似随机的图像中。项目->清理也没有帮助。我知道这一定是我的机器或 eclipse 安装的问题,因为它不会发生在我的工作机器上,只会发生在我的家用笔记本电脑上。
安装应用程序时没有任何问题,但如果能够看到布局更改而无需一遍又一遍地安装应用程序,那就太好了。
编辑
每当我在布局文件中使用自定义视图时,我也会收到这些消息:
error!
UnsupportedClassVersionError: Bad version number in .class file
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
Exception details are logged in Window > Show View > Error Log
I've been having this problem for a while:
Here is my header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<ImageView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/logo_text"/>
</LinearLayout>
And this what the Eclipse/Android XML viewer is giving me:
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
This happens in other projects as well for seemingly random images. Project->Clean doesn't help either. I know this has to be an issue with my machine or eclipse installation because it doesn't happen on my work machine, only my home laptop.
There are no problems when the app is installed, but it would be nice to be able to see layout changes without having to install the app over and over again.
EDIT
I also get these messages anytime I use a custom View in a layout file:
error!
UnsupportedClassVersionError: Bad version number in .class file
Unable to resolve drawable "C:\Users\Me\MyApp\res\drawable-hdpi\logo_text.png" in attribute "src"
Exception details are logged in Window > Show View > Error Log
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当我将新图像导入到我的项目中时,有时会遇到这样奇怪的问题。您是否还有其他包含该文件不同版本的 res-image 目录?您可以尝试删除 png 并重新添加到项目中。
I sometimes have weird issues like this when importing new images into my project. Do you have any other res-image directories with different versions of this file? You may try removing the png and re-adding to the project.
错误消息明确提到了可绘制目录的 -hdpi 版本。您是否在所有不同版本的可绘制目录中都获得了该图像?也许它在 res/drawable-ldpi 或 res/drawable-mdpi 中,但不在 res/drawable-hdpi 中?
如果您还没有,您可以创建一个普通的 res/drawable 文件夹并在其中添加图像,然后人们会期望系统在找不到特定于定义的版本时回退到该文件夹。
The error message explicitly mentions the -hdpi version of the drawable directory. Have you got that image in all of the different versions of the drawable directory? Perhaps it is in res/drawable-ldpi or res/drawable-mdpi but not res/drawable-hdpi?
If you don't already have one, you could create a plain res/drawable folder and add the image there, then one would expect the system to fall back to that whenever it didn't find a definition-specific version.
实际上尝试在 ImageView 上放置一个 id 标签:
android:id=:"@+id/imageView"
。告诉我它是否有效。Actually try to put an id tag on ImageView :
android:id=:"@+id/imageView"
.Tell me if it is working or not.