title: Widget unfortunately has stopped android
body: <p>I have a problem, Emulator shows alert dialog "Unfortunately, AppName has stopped" Thanks for help. I'd like to create clock widget.</p>
  
  <p><strong>RmWidget.java</strong></p>
  
  <blockquote>
    <p>package lek.runningman.widget;</p>
  
  <pre><code>import java.text.SimpleDateFormat;
  import java.util.Date;
  import android.appwidget.AppWidgetManager;
  import android.appwidget.AppWidgetProvider;
  import android.content.Context;
  import android.widget.RemoteViews;
  
  public class RmWidget extends AppWidgetProvider {
    // Define the format string for the date
  
    private SimpleDateFormat formatter = new SimpleDateFormat(
        "hh:mm:ss\nEEEEEEEE\nd-MMM-yyyy");
  
    @Override
    public void onUpdate(Context context,AppWidgetManager appWidgetManager, int[] appWidgetIds) {
  
    // Retrieve and format the current date
    String now = formatter.format(new Date());
  
    // Change the text in the widget
    RemoteViews updateViews = new RemoteViews(
    context.getPackageName(), R.layout.main);
    updateViews.setTextViewText(R.id.text, now);
    appWidgetManager.updateAppWidget(appWidgetIds, updateViews);
  
    //super.onUpdate(context, appWidgetManager, appWidgetIds);
    onUpdate(context, appWidgetManager, appWidgetIds);
  
    }
  }
  </code></pre>
  </blockquote>
  
  <p><strong>widget.xml</strong></p>
  
  <blockquote>
    <p>
        
  
  <pre><code>android:minWidth="220dip"
  android:minHeight="146dip"
  android:updatePeriodMillis="1000"
  android:initialLayout="@layout/main"&gt;
  &lt;/appwidget-provider&gt;
  </code></pre>
  </blockquote>
  
  <p><strong>main.xml</strong></p>
  
  <blockquote>
    <p>
        </p>
  
  <pre><code>&lt;TextView
      android:id="@+id/text"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center_horizontal"
      android:text="@string/app_name"
      android:textStyle="bold"
  
        android:typeface="monospace"
      android:textColor="@android:color/white"
      android:textSize="18sp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  </blockquote>
  
  <p><strong>RmWidget Manefest.xml</strong></p>
  
  <blockquote>
    <p>
        </p>
  
  <pre><code>    &lt;uses-sdk android:minSdkVersion="15" /&gt;
  
      &lt;application
          android:icon="@drawable/icon"
          android:label="@string/app_name" &gt;
          &lt;receiver 
              android:name=".RmWidget"
              android:label="@string/widget_name" &gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
            &lt;/intent-filter&gt;
  
              &lt;meta-data android:name="android.appwidget.provider"
                       android:resource="@xml/widget" /&gt;
  
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  </blockquote>