android xml:未能解析文件,无法解析android的XML文件

博主在进行Android应用开发时遇到了一个资源解析错误,具体涉及button1.xml和main.xml文件。错误信息指出tag缺少'drawable'属性或子标签定义。经过尝试和排查,包括更换图片资源和调整代码,最终问题得到解决。错误可能是由于XML文件格式不正确或者资源引用方式有误导致。
摘要由CSDN通过智能技术生成

我基本上是全新的,并在书中通过一个例子.

我的button1.xml看起来像这样….

android:drawable="@drawable/buttonpressed" />

android:drawable="@drawable/buttonfocused" />

main.xml中…

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:id="@+id/button_one"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingTop="5px"

android:src="@drawable/button1">

而且我一直收到这个错误

eclipse.buildId=M20110909-1335

java.version=1.7.0_01

java.vendor=Oracle Corporation

BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US

Command-line arguments: -os win32 -ws win32 -arch x86_64

Error

Tue Oct 25 12:19:07 CDT 2011

main.xml: Failed to parse file C:\Users\kpreese\workspace\Chapter7\res\drawable\button1.xml

org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: tag requires a 'drawable' attribute or child tag defining a drawable

at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:178)

at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:832)

at android.graphics.drawable.Drawable.createFromXml(Drawable.java:769)

at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:208)

at com.android.layoutlib.bridge.android.BridgeTypedArray.getDrawable(BridgeTypedArray.java:775)

at android.widget.ImageView.(ImageView.java:118)

at android.widget.ImageButton.(ImageButton.java:85)

at android.widget.ImageButton.(ImageButton.java:81)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at android.view.LayoutInflater.createView(LayoutInflater.java:576)

at com.android.layoutlib.bridge.android.BridgeInflater.onCreateView(BridgeInflater.java:84)

at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)

at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)

at com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:129)

at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:83)

at android.view.LayoutInflater.rInflate(LayoutInflater.java:702)

at android.view.LayoutInflater.inflate(LayoutInflater.java:479)

at android.view.LayoutInflater.inflate(LayoutInflater.java:367)

at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:324)

at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:321)

at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)

at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)

at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1317)

at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1071)

at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$ConfigListener.onConfigurationChange(GraphicalEditorPart.java:493)

at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.onTargetChange(GraphicalEditorPart.java:973)

at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.onDescriptorsChanged(LayoutEditor.java:568)

at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.initUiRootNode(LayoutEditor.java:490)

at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.updateEditor(GraphicalEditorPart.java:787)

at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.onTargetLoaded(GraphicalEditorPart.java:752)

at com.android.ide.eclipse.adt.AdtPlugin$11.run(AdtPlugin.java:1613)

at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)

at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)

at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)

at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)

at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)

at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)

at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)

at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)

at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)

at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)

at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)

at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)

at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)

at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)

at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)

at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)

at org.eclipse.equinox.launcher.Main.run(Main.java:1410)

at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

我似乎无法弄清楚这一点.我搜索并发现了许多类似的问题,但自己没有发现任何错误.有什么建议?

– 我确实尝试切换两个文件(按下按钮和按钮),但仍然在同一行代码中收到错误.然后用ic_launcher文件替换了所有文件,这也导致了同样的错误.如果我设置android.src =“#00000000”它确实有效.我不知道这是否有帮助,但似乎表明问题不是文件,而是在button1.xml代码中.

所以我认为我已经修好了.我不确定我做了什么,但重新输入了

机器人:SRC = “@绘制/ button1的” >

线.它有效.谢谢你们的帮助!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值