Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:30:19+00:00 2026-06-05T09:30:19+00:00

I have AsyncTask extend class I want to display progress dialoge so I use

  • 0

I have AsyncTask extend class I want to display progress dialoge so I use the following code

 class EncounterBackgroundWorker extends AsyncTask<Void, Void, Void> {

      ProgressDialog connectionProgressDialog;
      @Override
      protected void onPreExecute() {


          connectionProgressDialog = new ProgressDialog(null);
          connectionProgressDialog.setCancelable(false);
          connectionProgressDialog.setCanceledOnTouchOutside(false);
          connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
          connectionProgressDialog.setMessage("Uploading Leads...");
          connectionProgressDialog.show();
      }
}

call it in

public class ChemoUnit  extends Fragment {


    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {


         View view = inflater.inflate(
                    R.layout.chemounit,
                    container,
                    false);


        //Intialize the record Grid
         LinearLayout formLayout = (LinearLayout)view.findViewById(R.id.ChemoUnitGrid);
        formLayout.removeAllViews();

        MainGrid = new ListView(getActivity().getApplicationContext());              
        MainGrid.setVisibility(ListView.VISIBLE);
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                 LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
         params.gravity = Gravity.RIGHT;
         MainGrid.setLayoutParams(params);



         //1. set the header 

         ViewGroup header = (ViewGroup)inflater.inflate(R.layout.chemounitgridheader, MainGrid, false);
         MainGrid.addHeaderView(header, null, false);

         //2. Call the web Service 


         new EncounterBackgroundWorker( getActivity()).execute();

         MainGrid.setAdapter(new Encounteradapter(view.getContext(), null));
        // Finally add it 

         formLayout.addView(MainGrid);



         // Return the Result 
        return inflater.inflate(R.layout.chemounit, container, false);
    }



}

but it always crash , I don’t know how initialize the progress and add context to i1t , give this log

06-10 14:49:48.665: D/dalvikvm(10728): GC_CONCURRENT freed 143K, 4% free 6768K/6983K, paused 3ms+4ms
06-10 14:49:51.465: D/dalvikvm(10728): GC_FOR_ALLOC freed 46K, 4% free 6824K/7047K, paused 39ms
06-10 14:49:51.465: I/dalvikvm-heap(10728): Grow heap (frag case) to 7.223MB for 513744-byte allocation
06-10 14:49:51.505: D/dalvikvm(10728): GC_FOR_ALLOC freed <1K, 4% free 7326K/7559K, paused 25ms
06-10 14:49:51.535: I/System.out(10728): Chemo Unit
06-10 14:49:51.540: I/System.out(10728): Next Appointement
06-10 14:49:51.545: I/System.out(10728): Change Booking
06-10 14:49:51.545: I/System.out(10728): Booking
06-10 14:49:51.550: D/dalvikvm(10728): GC_CONCURRENT freed 3K, 3% free 7353K/7559K, paused 2ms+4ms
06-10 14:49:51.555: I/System.out(10728): Chemo Unit
06-10 14:49:51.555: I/System.out(10728): Next Appointement
06-10 14:49:51.560: I/System.out(10728): Change Booking
06-10 14:49:51.565: I/System.out(10728): Booking
06-10 14:49:51.565: I/System.out(10728): Chemo Unit
06-10 14:49:51.570: I/System.out(10728): Next Appointement
06-10 14:49:51.570: I/System.out(10728): Change Booking
06-10 14:49:51.570: I/System.out(10728): Booking
06-10 14:49:51.575: I/System.out(10728): Chemo Unit
06-10 14:49:51.575: I/System.out(10728): Next Appointement
06-10 14:49:51.585: I/System.out(10728): Change Booking
06-10 14:49:51.590: I/System.out(10728): Booking
06-10 14:49:51.590: I/System.out(10728): Chemo Unit
06-10 14:49:51.595: I/System.out(10728): Next Appointement
06-10 14:49:51.595: I/System.out(10728): Change Booking
06-10 14:49:51.600: I/System.out(10728): Booking
06-10 14:49:55.410: D/CLIPBOARD(10728): Hide Clipboard dialog at Starting input: finished by someone else... !
06-10 14:50:00.075: I/System.out(10728): Chemo Unit
06-10 14:50:00.080: I/System.out(10728): Next Appointement
06-10 14:50:00.085: I/System.out(10728): Change Booking
06-10 14:50:00.090: I/System.out(10728): Booking
06-10 14:50:00.090: I/System.out(10728): Chemo Unit
06-10 14:50:00.090: I/System.out(10728): Next Appointement
06-10 14:50:00.095: I/System.out(10728): Change Booking
06-10 14:50:00.095: I/System.out(10728): Booking
06-10 14:50:00.100: I/System.out(10728): Chemo Unit
06-10 14:50:00.100: I/System.out(10728): Next Appointement
06-10 14:50:00.105: I/System.out(10728): Change Booking
06-10 14:50:00.105: I/System.out(10728): Booking
06-10 14:50:00.105: I/System.out(10728): Chemo Unit
06-10 14:50:00.105: I/System.out(10728): Next Appointement
06-10 14:50:00.105: I/System.out(10728): Change Booking
06-10 14:50:00.110: I/System.out(10728): Booking
06-10 14:50:01.995: I/System.out(10728): Chemo Unit
06-10 14:50:01.995: I/System.out(10728): Next Appointement
06-10 14:50:01.995: I/System.out(10728): Change Booking
06-10 14:50:02.005: I/System.out(10728): Booking
06-10 14:50:02.010: I/System.out(10728): Chemo Unit
06-10 14:50:02.010: I/System.out(10728): Next Appointement
06-10 14:50:02.010: I/System.out(10728): Change Booking
06-10 14:50:02.010: I/System.out(10728): Booking
06-10 14:50:02.015: I/System.out(10728): Chemo Unit
06-10 14:50:02.015: I/System.out(10728): Next Appointement
06-10 14:50:02.015: I/System.out(10728): Change Booking
06-10 14:50:02.015: I/System.out(10728): Booking
06-10 14:50:02.020: I/System.out(10728): Chemo Unit
06-10 14:50:02.020: I/System.out(10728): Next Appointement
06-10 14:50:02.020: I/System.out(10728): Change Booking
06-10 14:50:02.020: I/System.out(10728): Booking
06-10 14:50:02.050: D/AndroidRuntime(10728): Shutting down VM
06-10 14:50:02.050: W/dalvikvm(10728): threadid=1: thread exiting with uncaught exception (group=0x401b4760)
06-10 14:50:02.050: E/AndroidRuntime(10728): FATAL EXCEPTION: main
06-10 14:50:02.050: E/AndroidRuntime(10728): java.lang.NullPointerException
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:120)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.app.AlertDialog.<init>(AlertDialog.java:80)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.app.ProgressDialog.<init>(ProgressDialog.java:76)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at com.appnetics.EncounterBackgroundWorker.onPreExecute(EncounterBackgroundWorker.java:45)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:549)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.os.AsyncTask.execute(AsyncTask.java:499)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at com.appnetics.ChemoUnit.onCreateView(ChemoUnit.java:63)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.os.Handler.handleCallback(Handler.java:587)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.os.Looper.loop(Looper.java:132)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at android.app.ActivityThread.main(ActivityThread.java:4123)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at java.lang.reflect.Method.invokeNative(Native Method)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at java.lang.reflect.Method.invoke(Method.java:491)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
06-10 14:50:02.050: E/AndroidRuntime(10728):    at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:30:22+00:00Added an answer on June 5, 2026 at 9:30 am

    You must pass Context object to ProgressTask.

    Change this

    connectionProgressDialog = new ProgressDialog(null);
    

    to

    connectionProgressDialog = new ProgressDialog(context);
    

    Now next questions comes is how will i get the context.

    Change your code to include context argument constructer.

    class EncounterBackgroundWorker extends AsyncTask<Void, Void, Void> {
    
          private ProgressDialog connectionProgressDialog;
          private Context context;
    
          public EncounterBackgroundWorker(Context context){
             this.context=context;
          }
    
          @Override
          protected void onPreExecute() {
    
    
              connectionProgressDialog = new ProgressDialog(context);
              connectionProgressDialog.setCancelable(false);
              connectionProgressDialog.setCanceledOnTouchOutside(false);
              connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
              connectionProgressDialog.setMessage("Uploading Leads...");
              connectionProgressDialog.show();
          }
    }
    

    Change you calling code

    From

    new EncounterBackgroundWorker().execute();
    

    To

    new EncounterBackgroundWorker(getActivity()).execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code fragment: public static class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {
I have this AsyncTask: private class GetMyFlights extends AsyncTask<String, Void, Integer> { private ProgressDialog
I have this code: private class DownloadWebPageTask extends AsyncTask<String, Void, String> { @Override protected
I have this code so far: private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
I am trying to create downloading progress. I have my class which extends AsyncTask:
i have written the code like below public class SplashScreen extends BaseActivity{ public void
i have this class: public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { ImageFromWeb ifw;
I have a class that extends AsyncTask. In the doInBackground() method, I connect to
I have the following asynctask class which is not inside the activity. In the
I have a common class say for eg Class A which extends AsyncTask and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.