I am basically brand new to this and working through an example in a book. my button1.xml looks like this....
<?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/buttonpressed" />
<item android:state_focused="true"
android:drawable="@drawable/buttonfocused" />
<item android:drawable="@drawable/buttonnormal" />
</selector>
Main.xml...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageButton
android:id="@+id/button_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5px"
android:src="@drawable/button1">
</ImageButton>
</LinearLayout>
and I keep getting this error
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: <item> 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.<init>(ImageView.java:118)
at android.widget.ImageButton.<init>(ImageButton.java:85)
at android.widget.ImageButton.<init>(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)
I can't seem to figure this out. I searched and found many similar problems, but didn't find any of the errors myself. Any suggestions?
-- I did try switching two of the files (buttonpressed and buttonfocused) and still received the error at the same line of code. Then replaced all of the files with the ic_launcher file, this also resulted in the same error. If I set the android.src="#00000000" it does work. I don't know if this helps but seems to indicate the problem is not the files but in the button1.xml code.
so I got it fixed I think. I am not really sure what I did but retype the android:src="@drawable/button1"> line. and poof it works. Thank you both for your help!
I had the same issue. In my case there was a single space before the xml tag in the XML file (the source copied from the android developers web page) After I removed the space and readd the imagebutton everything went normal. I tried to reinsert the space and got the same error again.
Change
<ImageButton
android:id="@+id/button_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5px"
android:src="@drawable/button1">
to
<ImageButton
android:id="@+id/button_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5px"
android:background="@drawable/button1">
Notice that android:src="@drawable/button1"
is changed to android:background="@drawable/button1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With