可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
When loading a widget if it cannot find a resource or something it says Problem Loading Widget. That's all! Amazing! This message remains on the home screen and does not even say which widget it had trouble loading.
I figured it out by trial and error but I would like to know if there are any places to find the error message when this occurs. Where will Android say what problem it had loading the widget or even which widget it failed to load?
回答1:
As said in comments, check logcat. What you will see is a NullPointerException. I have had this before too.
回答2:
Check elements you used in the view in a Widget..
Documentation link
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
- FrameLayout
- LinearLayout
- RelativeLayout
- GridLayout
And the following widget classes:
- AnalogClock
- Button
- Chronometer
- ImageButton
- ImageView
- ProgressBar
- TextView
- ViewFlipper
- ListView
- GridView
- StackView
- AdapterViewFlipper
Using forbidden elements causes this very
Problem Loading Widget
message, without saying where did it happen.
回答3:
Yet another possible cause of this:
I saw this in the log:
Failed to resolve attribute
The issue was that I was attempting to use a colour from the current theme as the background to one of my layouts.
e.g
android:background="?themeColor"
Changing this to a specific colour resolved the issue.
android:background="@color/White"
回答4:
There is of course the use-case where there was a widget loaded on the home page and the user then uninstalls the application that contains the widget and widget config app.
When that happens, all you see is the "Problem Loading Widget" in a toast-like box on the home screen. As far as I can tell, the widget gets no indicatation that the package is being uninstalled and I guess then the home screen AppWidgetManager thows up a default message.
Not well thought out behaviour on the part of the OS team. I suggest that it would be better to call the widget's onDisbled() and onDestroy() methods before the package is removed so they can tidy up if need be and the user (non-geek phone user) gets a clean experience.
回答5:
I also face this problem but only due to heavy widget layout. Widget Layout should be light as much you can create. Now my widget working perfect.
回答6:
Problem Loading the widget results from problem/s in your widget layout!
There are only limited amount of resource you can use in the widget.Make sure you use the proper elements and their fields.
A RemoteViews object (and, consequently, an App Widget) can support the following ... widget classes:
AnalogClock
Button
...
Developer docs
My problem was: I had this Button's field which was not supported
android:onClick="onClick"
Deleting this enabled the widget to appear where placed (if placed previously) and in the menu of available widgets.
In fact setting android:onClick=
for any View
results in this error.
回答7:
A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:
FrameLayout
LinearLayout
RelativeLayout
GridLayout
And the following widget classes:
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper
Anything using other than above causes this so called "Problem Loading widget".
Moreover, check logs (without any filter) to see exact line of this problem.
回答8:
It may be caused by Moving of the specific (Widget) Application from Internal Memory to SD card
.(Android – Fixing “Problem Loading Widget” Error)
回答9:
I faced this problem because I was trying to use Check-box!
So,just remove checkbox
.
it will work fine.
回答10:
Just fixed another variant of this error not mentioned in the other answers.
Symptoms were:
1) "Problem loading widget" error on Gingerbread and below
2) The exact same build ran fine on ICS and Jellybean
3) No errors in logcat
The problem was caused by manipulating a view that was never inflated in the remoteviews. Specifically:
remoteviews.setViewVisibility(viewId, View.GONE);
Where viewId was a valid resource, but it was in a layout that was never added to the remote views. No errors were thrown, and the widget displayed 'Problem loading widget' after the call to .updateAppWidget()
回答11:
Basically Widgets swallow exceptions. Just set an appropriate filter in your logcat, and you'll be able to see what the problem is...
Above, I am just searching for the Word "Widget" and setting no filter on any specific application. It essentially gives me the Throwable.getMessage()
without the full stack trace.
回答12:
I had the same issue but the logcat did not show anything suspicious, neither an error nor a warning. Basically, I was calling a wrong method to change the color of the textview's text.
回答13:
I have same problem when i uninstall note app, i try to touch and hold the message and it shows remove menu, i choose remove than it disappear.
回答14:
I had the same issue. Problem resolved: I used custom view in widget. In my situation it was TextView with custom typeface.
回答15:
In my case I had a floating textView
over other views. Removing it and thinking of a different way of showing my info to the user with the existing views that are not overlapping was the solution.
So don't overlap views with RelativeLayout
, I still use it and it works, but the views are not overlapping as much as possible.
回答16:
Just for the record. I have a FrameLayout with a TextView inside, all content in a LinerLayout, that would be the header of my widget. Initially I had this
<LinearLayout
[...]
<FrameLayout
android:id="@+id/widget"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/app_name"
android:layout_margin="@dimen/activity_horizontal_margin"
android:textColor="@android:color/white"/>
</FrameLayout>
[...]
</LinearLayout>
As everyone here, I had the "Problem loading widget" message. The solution was change this
android:layout_height="?attr/actionBarSize"
for this:
android:layout_height="64dp"
回答17:
In my case error was caused by changed provider class name. So if you have changed the name of Widget Provider class, try to change it back. Also, if you have changed the names of xml files (ex. widget_info.xml
, widget_layout.xml
), you might want to change those back as well.
This happened only when user updated app and "old" widget was currently visible.
回答18:
I was also having the same problem -
I was using android.support.constraint.ConstraintLayout that's why it was saying "Problem loading widget" after removing this and changing to LinearLayout problem solved as @Gangnus saying, it will work for only specific views only.