从库视图错误引用的小部件

时间:2012-03-30 00:49:51

标签: android reference android-appwidget

所以我刚创建了一个新的应用程序,它引用了我的旧应用程序,将其用作库。你可以在这里看到问题/解决方案:

Alternate entry on Play Store

但是我刚才注意到,当我尝试设置一些小部件时,我的新应用程序给了我错误视图,其中包含LogCat输出:

03-29 20:48:17.899: E/AppWidgetHostView(456): Package name com.nickavv.cleanwidgets not found
03-29 20:48:17.899: E/RemoteViews(456): Package name com.nickavv.cleanwidgets not found
03-29 20:48:17.960: W/AppWidgetHostView(456): updateAppWidget couldn't find any view, using error view
03-29 20:48:17.960: W/AppWidgetHostView(456): android.view.InflateException: Binary XML file line #18: Error inflating class com.android.launcher2.AllApps3D
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.view.LayoutInflater.createView(LayoutInflater.java:513)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.widget.RemoteViews.apply(RemoteViews.java:930)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:155)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:218)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at com.android.launcher2.Launcher.completeAddAppWidget(Launcher.java:911)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at com.android.launcher2.Launcher.onActivityResult(Launcher.java:542)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.app.Activity.dispatchActivityResult(Activity.java:3890)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.app.ActivityThread.access$2800(ActivityThread.java:125)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.os.Handler.dispatchMessage(Handler.java:99)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.os.Looper.loop(Looper.java:123)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.app.ActivityThread.main(ActivityThread.java:4627)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at java.lang.reflect.Method.invokeNative(Native Method)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at java.lang.reflect.Method.invoke(Method.java:521)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at dalvik.system.NativeStart.main(Native Method)
03-29 20:48:17.960: W/AppWidgetHostView(456): Caused by: android.view.InflateException: Binary XML file line #18: Class not allowed to be inflated com.android.launcher2.AllApps3D
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:525)
03-29 20:48:17.960: W/AppWidgetHostView(456):   at android.view.LayoutInflater.createView(LayoutInflater.java:472)

这里发生了什么?感谢

1 个答案:

答案 0 :(得分:3)

答案在于我使用RemoteViews作为小部件,并且在设置一些远程视图时,我对原始应用程序中的软件包名称进行了硬编码。解决方案是使用context.getPackageName()

替换硬编码的包名称