“无法配置解析器”android

时间:2012-08-21 10:35:56

标签: android button textcolor

我有一个常规按钮,如下所示:

<Button
    android:id="@+id/button1"
    style="@style/ButtonInfo"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:text="Button" />

ButtonInfo如下所示:

 <style name="ButtonInfo" parent="@android:style/Widget.Button">
    <item name="android:background">@drawable/button_info</item>
    <item name="android:textColor">@color/button_info_text</item>
    <item name="android:textSize">16dip</item>
</style>

color / button_info_text.xml如下所示:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"><shape>
        <solid android:color="@color/black" />
    </shape></item>
<item><shape>
        <solid android:color="@color/white" />
    </shape></item>
</selector>

我一直在错误日志中找到它:

eclipse.buildId=M20120208-0800
java.version=1.7.0_05
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=es_ES
Command-line arguments:  -os win32 -ws win32 -arch x86 -clean

Error
Tue Aug 21 12:17:57 CEST 2012
layout_guiacolor_info.xml: Failed to configure parser for C:\Documents and Settings\sanriv\Escritorio\GuiaColor\android\GuiaColor\res\drawable\button_info_text.xml

org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <item> tag requires a 'android:color' attribute.
    at android.content.res.ColorStateList.inflate(ColorStateList.java:226)
    at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
    at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
    at com.android.layoutlib.bridge.android.BridgeTypedArray.getColorStateList(BridgeTypedArray.java:338)
    at android.widget.TextView.<init>(TextView.java:628)
    at android.widget.Button.<init>(Button.java:108)
    at android.widget.Button.<init>(Button.java:104)
    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:500)
    at com.android.layoutlib.bridge.android.BridgeInflater.onCreateView(BridgeInflater.java:84)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    at com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:129)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:279)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:318)
    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:1640)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1391)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$ConfigListener.onConfigurationChange(GraphicalEditorPart.java:706)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.onTargetChange(GraphicalEditorPart.java:1293)
    at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.onDescriptorsChanged(LayoutEditorDelegate.java:912)
    at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegateInitUiRootNode(LayoutEditorDelegate.java:831)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.updateEditor(GraphicalEditorPart.java:1052)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.onTargetLoaded(GraphicalEditorPart.java:1016)
    at com.android.ide.eclipse.adt.AdtPlugin$10.run(AdtPlugin.java:1704)
    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:2701)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
    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)

当我尝试运行它时,我得到了这个例外:

08-21 12:12:18.370: E/AndroidRuntime(14337): FATAL EXCEPTION: main
08-21 12:12:18.370: E/AndroidRuntime(14337): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cidaut.guiacolor/com.cidaut.guiacolor.controller.InfoActivity}: android.view.InflateException: Binary XML file line #37: Error inflating class <unknown>
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2079)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.ActivityThread.access$600(ActivityThread.java:132)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.os.Looper.loop(Looper.java:137)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.ActivityThread.main(ActivityThread.java:4575)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at java.lang.reflect.Method.invokeNative(Native Method)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at java.lang.reflect.Method.invoke(Method.java:511)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at dalvik.system.NativeStart.main(Native Method)
08-21 12:12:18.370: E/AndroidRuntime(14337): Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class <unknown>
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.view.LayoutInflater.createView(LayoutInflater.java:606)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.Activity.setContentView(Activity.java:1835)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at com.cidaut.guiacolor.controller.InfoActivity.onCreate(InfoActivity.java:13)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.Activity.performCreate(Activity.java:4465)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2033)
08-21 12:12:18.370: E/AndroidRuntime(14337):    ... 11 more
08-21 12:12:18.370: E/AndroidRuntime(14337): Caused by: java.lang.reflect.InvocationTargetException
08-21 12:12:18.370: E/AndroidRuntime(14337):    at java.lang.reflect.Constructor.constructNative(Native Method)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.view.LayoutInflater.createView(LayoutInflater.java:586)
08-21 12:12:18.370: E/AndroidRuntime(14337):    ... 24 more
08-21 12:12:18.370: E/AndroidRuntime(14337): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/button_info_text.xml from color state list resource ID #0x7f020006
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.content.res.Resources.loadColorStateList(Resources.java:2113)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.widget.TextView.<init>(TextView.java:774)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.widget.Button.<init>(Button.java:108)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.widget.Button.<init>(Button.java:104)
08-21 12:12:18.370: E/AndroidRuntime(14337):    ... 27 more
08-21 12:12:18.370: E/AndroidRuntime(14337): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <item> tag requires a 'android:color' attribute.
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.content.res.ColorStateList.inflate(ColorStateList.java:226)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.content.res.ColorStateList.createFromXmlInner(ColorStateList.java:150)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.content.res.ColorStateList.createFromXml(ColorStateList.java:129)
08-21 12:12:18.370: E/AndroidRuntime(14337):    at android.content.res.Resources.loadColorStateList(Resources.java:2110)
08-21 12:12:18.370: E/AndroidRuntime(14337):    ... 31 more

我做错了什么?

1 个答案:

答案 0 :(得分:3)

读取错误跟踪的第一行:

org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <item> tag requires a 'android:color' attribute.

显然,您的代码需要android:color 属性

或者可能: Error : <item> tag requires a 'drawable' attribute or child tag defining a drawable