当我尝试在模拟器中添加小部件时,会出现一堆错误。可能是什么问题?
这是小部件的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1" android:background="@layout/widget_layout">
<FrameLayout android:id="@+id/frameLayout1" android:layout_height="200dp" android:layout_width="160dp" android:background="@drawable/framep">
<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:layout_width="wrap_content" android:text="TextView" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginLeft="24dp" android:layout_marginTop="22dp" android:id="@+id/widDay" android:textColor="@color/colorBlack"></TextView>
<TextView android:text="TextView" android:layout_below="@+id/widDay" android:layout_alignLeft="@+id/widDay" android:layout_marginTop="15dp" android:id="@+id/widText" android:layout_height="120dp" android:layout_width="115dp" android:textColor="@color/colorBlack"></TextView>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
以下是错误:
07-20 22:57:52.142: WARN/AppWidgetHostView(130): Error inflating AppWidget AppWidgetProviderInfo(provider=ComponentInfo{com.geft.timetable/com.geft.timetable.WatchWidget}): android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
07-20 22:57:52.222: WARN/InputManagerService(61): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@406c0a50
07-20 22:57:52.352: WARN/AppWidgetHostView(130): updateAppWidget couldn't find any view, using error view
07-20 22:57:52.352: WARN/AppWidgetHostView(130): android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.widget.RemoteViews.apply(RemoteViews.java:939)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:218)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:250)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:73)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.os.Looper.loop(Looper.java:123)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at java.lang.reflect.Method.invokeNative(Native Method)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at java.lang.reflect.Method.invoke(Method.java:507)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at dalvik.system.NativeStart.main(Native Method)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): Caused by: java.lang.reflect.InvocationTargetException
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at java.lang.reflect.Constructor.constructNative(Native Method)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): ... 16 more
07-20 22:57:52.352: WARN/AppWidgetHostView(130): Caused by: android.content.res.Resources$NotFoundException: File res/layout/widget_layout.xml from drawable resource ID #0x7f030002
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.content.res.Resources.loadDrawable(Resources.java:1697)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.view.View.<init>(View.java:1951)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.view.View.<init>(View.java:1899)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.view.ViewGroup.<init>(ViewGroup.java:286)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.widget.LinearLayout.<init>(LinearLayout.java:120)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): ... 19 more
07-20 22:57:52.352: WARN/AppWidgetHostView(130): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag LinearLayout
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:783)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): at android.content.res.Resources.loadDrawable(Resources.java:1694)
07-20 22:57:52.352: WARN/AppWidgetHostView(130): ... 24 more
07-20 22:57:52.372: WARN/AppWidgetHostView(130): updateAppWidget couldn't find any view, using error view
07-20 22:57:52.372: WARN/AppWidgetHostView(130): android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.LinearLayout
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.widget.RemoteViews.apply(RemoteViews.java:939)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:218)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:250)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:73)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.os.Looper.loop(Looper.java:123)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at java.lang.reflect.Method.invokeNative(Native Method)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at java.lang.reflect.Method.invoke(Method.java:507)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at dalvik.system.NativeStart.main(Native Method)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): Caused by: java.lang.reflect.InvocationTargetException
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at java.lang.reflect.Constructor.constructNative(Native Method)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): ... 16 more
07-20 22:57:52.372: WARN/AppWidgetHostView(130): Caused by: android.content.res.Resources$NotFoundException: File res/layout/widget_layout.xml from drawable resource ID #0x7f030002
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.content.res.Resources.loadDrawable(Resources.java:1697)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.view.View.<init>(View.java:1951)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.view.View.<init>(View.java:1899)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.view.ViewGroup.<init>(ViewGroup.java:286)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.widget.LinearLayout.<init>(LinearLayout.java:120)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): ... 19 more
07-20 22:57:52.372: WARN/AppWidgetHostView(130): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag LinearLayout
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:783)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): at android.content.res.Resources.loadDrawable(Resources.java:1694)
07-20 22:57:52.372: WARN/AppWidgetHostView(130): ... 24 more
答案 0 :(得分:6)
错误消息抱怨加载drawable。您的XML正在尝试使用名为@layout/widget_layout
的资源作为其背景。看起来你不小心尝试使用布局资源而不是drawable作为背景。