public static voID updateAppWidget(Context context,int ID,WALL_POST_DETAILS post){ try{ System.out.println("In updateAppWidget==>"+ID); AppWidgetManager mngr=AppWidgetManager.getInstance(context); String diff=diff(post.created_time.trim()); RemoteVIEws vIEws=new RemoteVIEws(context.getPackagename(),R.layout.Widget_layout); PendingIntent pending=PendingIntent.getActivity(context,new Intent(context,ShareDialogActivity.class),0); vIEws.setonClickPendingIntent(R.ID.TextVIEw01,pending); vIEws.setonClickPendingIntent(R.ID.button03,pending); vIEws.setTextVIEwText(R.ID.actor_name,post.actor_name); vIEws.setTextVIEwText(R.ID.actor_message,post.message); vIEws.setimageVIEwBitmap(R.ID.actor_photo,post.image); vIEws.setTextVIEwText(R.ID.created_time,diff); if(post.no_of_comments>0){ vIEws.setVIEwVisibility(R.ID.comments_image,VIEw.VISIBLE); vIEws.setVIEwVisibility(R.ID.comment_word,VIEw.VISIBLE); vIEws.setTextVIEwText(R.ID.no_of_comments,String.valueOf(post.no_of_comments)); vIEws.setVIEwVisibility(R.ID.no_of_comments,VIEw.VISIBLE); System.out.println("No. of Comments==>"+post.no_of_comments); }else{ vIEws.setVIEwVisibility(R.ID.comments_image,VIEw.INVISIBLE); vIEws.setVIEwVisibility(R.ID.comment_word,VIEw.INVISIBLE); vIEws.setTextVIEwText(R.ID.no_of_comments,String.valueOf("")); vIEws.setVIEwVisibility(R.ID.no_of_comments,VIEw.INVISIBLE); } if(post.no_of_likes>0){ vIEws.setVIEwVisibility(R.ID.likes_image,VIEw.VISIBLE); vIEws.setVIEwVisibility(R.ID.likes_word,VIEw.VISIBLE); vIEws.setTextVIEwText(R.ID.no_of_likes,String.valueOf(post.no_of_likes)); vIEws.setVIEwVisibility(R.ID.no_of_likes,VIEw.VISIBLE); }else{ vIEws.setVIEwVisibility(R.ID.likes_image,VIEw.INVISIBLE); vIEws.setVIEwVisibility(R.ID.likes_word,VIEw.INVISIBLE); vIEws.setTextVIEwText(R.ID.no_of_likes,String.valueOf("")); vIEws.setVIEwVisibility(R.ID.no_of_likes,VIEw.INVISIBLE); } Intent intent_next=new Intent(context,Getpostservice.class); Bundle b_next=new Bundle(); b_next.putInt(MyWidgetProvIDer.APP_Widget_ID,ID); b_next.putInt(MyWidgetProvIDer.REQUEST_CODE,MyWidgetProvIDer.NEXT_FB_POST); intent_next.putExtras(b_next); PendingIntent nextpostservice=PendingIntent.getService(context,MyWidgetProvIDer.NEXT_FB_POST,intent_next,PendingIntent.FLAG_UPDATE_CURRENT); vIEws.setonClickPendingIntent(R.ID.next_button,nextpostservice); Intent intent_prev=new Intent(context,Getpostservice.class); Bundle b_prev=new Bundle(); b_prev.putInt(MyWidgetProvIDer.APP_Widget_ID,ID); b_prev.putInt(MyWidgetProvIDer.REQUEST_CODE,MyWidgetProvIDer.PREV_FB_POST); intent_prev.putExtras(b_prev); PendingIntent prevpostservice=PendingIntent.getService(context,MyWidgetProvIDer.PREV_FB_POST,intent_prev,PendingIntent.FLAG_UPDATE_CURRENT); vIEws.setonClickPendingIntent(R.ID.prev_button,prevpostservice); Intent intent_comment=new Intent(context,FBShowCommentsActivity.class); Bundle b_comment=new Bundle(); b_comment.putInt(MyWidgetProvIDer.APP_Widget_ID,ID); b_comment.putInt(MyWidgetProvIDer.REQUEST_CODE,MyWidgetProvIDer.SHOW_COMMENTS); b_comment.putString(MyWidgetProvIDer.POST_ID,SessionStore.restoreCurrentPostID(context)); intent_comment.putExtras(b_comment); PendingIntent fbActionActivity=PendingIntent.getActivity(context,MyWidgetProvIDer.SHOW_COMMENTS,intent_comment,PendingIntent.FLAG_UPDATE_CURRENT); vIEws.setonClickPendingIntent(R.ID.comment_word,fbActionActivity); vIEws.setonClickPendingIntent(R.ID.comments_image,fbActionActivity); vIEws.setonClickPendingIntent(R.ID.no_of_comments,fbActionActivity); Intent intent_likes=new Intent(context,ShowlikeDialogActivity.class); Bundle b_likes=new Bundle(); b_likes.putInt(MyWidgetProvIDer.APP_Widget_ID,ID); b_likes.putInt(MyWidgetProvIDer.REQUEST_CODE,MyWidgetProvIDer.SHOW_liKES); b_likes.putString(MyWidgetProvIDer.POST_ID,SessionStore.restoreCurrentPostID(context)); intent_likes.putExtras(b_likes); PendingIntent fblikesActivity=PendingIntent.getActivity(context,MyWidgetProvIDer.SHOW_liKES,intent_likes,PendingIntent.FLAG_UPDATE_CURRENT); vIEws.setonClickPendingIntent(R.ID.likes_word,fblikesActivity); vIEws.setonClickPendingIntent(R.ID.likes_image,fblikesActivity); vIEws.setonClickPendingIntent(R.ID.no_of_likes,fblikesActivity); mngr.updateAppWidget(ID,vIEws); }catch(Exception e){ e.printstacktrace(); System.out.println("Exception==>"+e.getMessage()); }}
AppWidget已从Getpostservice待处理服务成功更新.在安装后第一次启动Pending Activity时,我可以成功更新小部件.但是,如果我再次启动第二次,Activity正确启动,但AppWidget没有获得更新,它会抛出空指针异常.我正在从UI线程更新小部件(来自AsyncTask的onPostExecute()方法).
W/System.err( 522): at androID.Widget.RemoteVIEws$ReflectionAction.writetoPa rcel(RemoteVIEws.java:400) W/System.err( 522): at androID.Widget.RemoteVIEws.writetoParcel(RemoteVIEws. java:1012) W/System.err( 522): at com.androID.internal.appWidget.IAppWidgetService$Stub $Proxy.updateAppWidgetIDs(IAppWidgetService.java:374) W/System.err( 522): at androID.appWidget.AppWidgetManager.updateAppWidget(Ap pWidgetManager.java:246) W/System.err( 522): at androID.appWidget.AppWidgetManager.updateAppWidget(Ap pWidgetManager.java:265) W/System.err( 522): at com.mobisys.androID.app_Widget.MyWidgetProvIDer.updat eAppWidget(MyWidgetProvIDer.java:185) W/System.err( 522): at com.mobisys.androID.app_Widget.MyWidgetProvIDer.onRec eive(MyWidgetProvIDer.java:71) W/System.err( 522): at androID.app.ActivityThread.handleReceiver(ActivityThr ead.java:1769) W/System.err( 522): at androID.app.ActivityThread.access$2400(ActivityThread .java:117) W/System.err( 522): at androID.app.ActivityThread$H.handleMessage(ActivityTh read.java:978) W/System.err( 522): at androID.os.Handler.dispatchMessage(Handler.java:99) W/System.err( 522): at androID.os.Looper.loop(Looper.java:123) W/System.err( 522): at androID.app.ActivityThread.main(ActivityThread.java:3 647) W/System.err( 522): at java.lang.reflect.Method.invokeNative(Native Method) W/System.err( 522): at java.lang.reflect.Method.invoke(Method.java:507) W/System.err( 522): at com.androID.internal.os.ZygoteInit$MethodAndArgsCalle r.run(ZygoteInit.java:839) W/System.err( 522): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.ja va:597)
W/System.err( 522): at dalvik.system.NativeStart.main(Native Method)
我从Pending Activity中按以下方式调用updateAppWidget静态方法:
MyWidgetProvIDer.updateAppWidget(context,mAppWidgetID,post); //context is pending Activity's instance
可能是什么问题?
提前致谢.
解决方法 我有完全相同的问题和堆栈跟踪.原因是我在setimageVIEwBitmap中传递了一个null Bitmap.答案可能为时已晚,但我认为你应该仔细检查这一行:
vIEws.setimageVIEwBitmap(R.ID.actor_photo,post.image);
如果我正确post.image将为null – 您应该删除此行或提供非空位图.
问候
总结以上是内存溢出为你收集整理的android – UpdateAppWidget Null Pointer Exception全部内容,希望文章能够帮你解决android – UpdateAppWidget Null Pointer Exception所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)