title: Android : Widget - Null pointer Exception when using setOnclickPendingIntent on the remoteviews?
body: <p>I got a Widget ( appwidgetprovider + service)
  This service updates the UI basically like this : </p>
  
  <pre><code>RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
  //doing some stuff like which works without any errors : 
  views.setTextViewText(R.id.Time, time);
  
  // Here I'm calling a static method that set pendingIntent on different ID  :
  // With it : Null Pointer Exception, without not.
  views = HomeWidgetUtils.setPendingIntentForAllWidgetSubView(context, views);
  
  //update AppWidgetProvider : 
  AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
  ComponentName thisAppWidget = new ComponentName(context, WDWidgetProvider.class);
  manager.updateAppWidget(widget, views);
  </code></pre>
  
  <p>So Everything works fine without using my static method that set PendingIntent to id, 
  setPendingIntentForAllWidgetSubView
  Here is the code : </p>
  
  <pre><code>public static RemoteViews setPendingIntentForAllWidgetSubView(Context context,RemoteViews rv){
      rv.setOnClickPendingIntent(R.id.Widget, HomeWidgetUtils.getPendingIntentonActivity(context, WeatherForecast.class));
  
  rv.setOnClickPendingIntent(R.id.globallayout, HomeWidgetUtils.getPendingIntentonActivity(context, TabActivity01.class));
      return rv;
  }
  
  public static  PendingIntent getPendingIntentonActivity(Context context,Class C) {
      Intent intentleft = new Intent(context, C);
      intentleft.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      return PendingIntent.getActivity(context, 1, intentleft,PendingIntent.FLAG_UPDATE_CURRENT);
  }
  </code></pre>
  
  <p>If I use it , here is the NPE I Got : ( line 283 is related to manager.updateAppWidget(widget, views); )</p>
  
  <pre><code>java.lang.NullPointerException
  at android.widget.RemoteViews$SetOnClickPendingIntent.writeToParcel(RemoteViews.java:131)
  at android.widget.RemoteViews.writeToParcel(RemoteViews.java:1003)
  at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetIds(IAppWidgetService.java:374)
  at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:246)
  at fr.cdcorp.homewidget.clock.ClockWidgetService.update(ClockWidgetService.java:283)
  at fr.cdcorp.homewidget.clock.ClockWidgetService$1.onReceive(ClockWidgetService.java:312)
  at  android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:892)
  at android.os.Handler.handleCallback(Handler.java:587)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:4627)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Furthermore, I'm sure widget and views are not null in  manager.updateAppWidget(widget, views) instruction.
  So What Am I doing Wrong when setting pendingIntent ????</p>
  
  <p>Any Helps would be appreciate !!!
  CD.</p>
  
  <p>Working solution (according to post author):</p>
  
  <pre><code>public static PendingIntent getPendingIntentonActivity(Context context,Class C) { 
      PendingIntent mPendingIntent = null; 
      Intent mIntent = new Intent(Intent.ACTION_MAIN).addCategory(
           Intent.CATEGORY_LAUNCHER); 
      ComponentName cn = new ComponentName(context, C); 
      mIntent.setComponent(cn); 
      return PendingIntent.getActivity(context, 0, mIntent, 
          PendingIntent.FLAG_UPDATE_CURRENT); 
  }
  </code></pre>