Woops... my BarAsyncTask class didn't have the line of code wrapped in a method... Oh well, you get the idea. That's what happens when answering questions late at night.
Thanks, Justin Anderson MagouyaWare Developer http://sites.google.com/site/magouyaware On Sat, Mar 19, 2011 at 1:31 AM, Justin Anderson <magouyaw...@gmail.com>wrote: > Looking at your code again I think I know what the problem is.... don't use > getApplicationContext(). It does nothing but cause issues. Your service > class extends Context so you can just pass a reference to your Service. > > Doing this depends on how you have your AsyncTask class set up... If it is > in a separate file just have the constructor take a Context and pass "this", > or if the ASyncTask class is a nested class, you can do this: > > public class FooService extends Service > { > ..... > > public class BarAsyncTask extends AsyncTask > { > * long > current_post=SessionStore.restoreCurrentPostTimeStamp(FooService.this);* > > } > } > > Thanks, > Justin Anderson > MagouyaWare Developer > http://sites.google.com/site/magouyaware > > > On Sat, Mar 19, 2011 at 1:23 AM, Mahavir Jain <vir.j...@gmail.com> wrote: > >> Thanks Justin for reply. Following the stack trace: >> >> ERROR/AndroidRuntime(473): FATAL EXCEPTION: AsyncTask #1 >> ERROR/AndroidRuntime(473): java.lang.RuntimeException: An error occured >> while executing doInBackground() >> ERROR/AndroidRuntime(473): at >> android.os.AsyncTask$3.done(AsyncTask.java:200) >> ERROR/AndroidRuntime(473): at >> java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) >> ERROR/AndroidRuntime(473): at >> java.util.concurrent.FutureTask.setException(FutureTask.java:125) >> ERROR/AndroidRuntime(473): at >> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) >> ERROR/AndroidRuntime(473): at >> java.util.concurrent.FutureTask.run(FutureTask.java:138) >> ERROR/AndroidRuntime(473): at >> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) >> ERROR/AndroidRuntime(473): at >> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) >> ERROR/AndroidRuntime(473): at java.lang.Thread.run(Thread.java:1019) >> ERROR/AndroidRuntime(473): Caused by: java.lang.NullPointerException >> ERROR/AndroidRuntime(473): at >> java.net.URLEncoder.encode(URLEncoder.java:53) >> ERROR/AndroidRuntime(473): at >> com.facebook.android.Util.encodeUrl(Util.java:86) >> ERROR/AndroidRuntime(473): at >> com.facebook.android.Util.openUrl(Util.java:146) >> ERROR/AndroidRuntime(473): at >> com.mobisys.android.app_widget.FBQueryAsyncTask.doInBackground(FBQueryAsyncTask.java:50) >> ERROR/AndroidRuntime(473): at >> com.mobisys.android.app_widget.FBQueryAsyncTask.doInBackground(FBQueryAsyncTask.java:1) >> ERROR/AndroidRuntime(473): at >> android.os.AsyncTask$2.call(AsyncTask.java:185) >> ERROR/AndroidRuntime(473): at >> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306) >> >> Same thing runs very perfectly from my AppWidgets configure activity (with >> same parameters passed), but It does not run from the PendingIntent service. >> >> can I call, AsyncTask in PendingItent Service? >> >> Regards, >> Mahavir >> >> >> On Sat, Mar 19, 2011 at 12:36 PM, Justin Anderson >> <magouyaw...@gmail.com>wrote: >> >>> Look at the stack trace in logcat where you are getting the >>> nullpointerexception... There should be a "caused by" line that tells you >>> the file and line number causing the exception >>> >>> Thanks, >>> Justin Anderson >>> MagouyaWare Developer >>> http://sites.google.com/site/magouyaware >>> >>> >>> On Sat, Mar 19, 2011 at 12:58 AM, Mahavir Jain <vir.j...@gmail.com>wrote: >>> >>>> Hi, >>>> >>>> I have created the service PendingIntent and assigning it to some button >>>> in my AppWidget like this >>>> >>>> * Intent intent=new Intent(context,GetPostService.class); >>>> Bundle b=new Bundle(); >>>> b.putInt(MyWidgetProvider.APP_WIDGET_ID, id); >>>> b.putInt(MyWidgetProvider.REQUEST_CODE, >>>> MyWidgetProvider.NEXT_POST); >>>> intent.putExtras(b); >>>> * >>>> * PendingIntent >>>> nextPostService=PendingIntent.getService(context, 0, intent, >>>> PendingIntent.FLAG_UPDATE_CURRENT); >>>> views.setOnClickPendingIntent(R.id.next_button, >>>> nextPostService);* >>>> >>>> In my Service class, I am calling AsyncTask which performs some network >>>> operation and get the result. The code of service class onStart() is as >>>> below: >>>> >>>> *public void onStart(Intent intent, int startId) {* >>>> * int appWidgetId=-1,code=-1; >>>> Bundle b=intent.getExtras(); >>>> if(b!=null){ >>>> appWidgetId=b.getInt(MyWidgetProvider.APP_WIDGET_ID, -1); >>>> code=b.getInt(MyWidgetProvider.REQUEST_CODE, -1); >>>> System.out.println("Application Id==>"+appWidgetId); >>>> System.out.println("Request Code==>"+code); >>>> } >>>> else{ >>>> System.out.println("Fuck off==>"); >>>> } >>>> >>>> FBQueryAsyncTask asyncTask=new FBQueryAsyncTask(); >>>> long >>>> current_post=SessionStore.restoreCurrentPostTimeStamp(getApplicationContext()); >>>> asyncTask.execute(new String[]{"SELECT actor_id, message, >>>> created_time FROM stream WHERE source_id = me() AND created_time > >>>> "+current_post+" LIMIT 1"});* >>>> *}* >>>> >>>> Whenever I click Next Button, service get started, and it enters in >>>> onStart() method of service, but in doInBackground() task, it exits >>>> throwing >>>> null pointer exception. While this same AsyncTask runs very perfectly when >>>> called from the configure activity of my AppWidget. >>>> >>>> My question is can I called, AsyncTask in PendingItent Service? Am I >>>> missing something? >>>> >>>> Thanks in Advance. >>>> >>>> Regards, >>>> Mahavir >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Android Developers" group. >>>> To post to this group, send email to >>>> android-developers@googlegroups.com >>>> To unsubscribe from this group, send email to >>>> android-developers+unsubscr...@googlegroups.com >>>> For more options, visit this group at >>>> http://groups.google.com/group/android-developers?hl=en >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Android Developers" group. >>> To post to this group, send email to android-developers@googlegroups.com >>> To unsubscribe from this group, send email to >>> android-developers+unsubscr...@googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/group/android-developers?hl=en >> >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Developers" group. >> To post to this group, send email to android-developers@googlegroups.com >> To unsubscribe from this group, send email to >> android-developers+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en