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 8237291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:25:31+00:00 2026-06-07T19:25:31+00:00

I have an AsynTask that crashes the whole application when doInBackground method calls another

  • 0

I have an AsynTask that crashes the whole application when doInBackground method calls another class that tries to show an alertdialog.

The following is my AsynTask,

private class ReserveAppointmentTask extends AsyncTask<Void, Void, Void>{

    @Override
    protected void onPreExecute() {
        showDialog(RESERVING_PROGRESS_DIALOG);
    }

    @Override
    protected Void doInBackground(Void... params) {     
        WebServiceResponse.appointmentReservation(AppointmentConfirmationActivity.this, appointmentObj);
        return null;
    }

    @Override
    protected void onPostExecute(Void response) {
        removeDialog(RESERVING_PROGRESS_DIALOG);
    }

}

The WebserviceResponse.appointmentReservation method contains the following code and I know for a fact that it enters the if condition stated below,

public static void appointmentReservation(AppointmentConfirmationActivity activity, Appointment appointmentObj){
    SetAppointmentResponse setAppointmentResponse = SetAppointmentResponse.extractJSONResponse(response);

    if(setAppointmentResponse.checkResponse()== RESPONSES.SUCCESSFULL){
        Dialogs.initAppointmentReservedDialog(activity);                            
    }

}

The Dialogs.initAppointmentReservedDialog contains the following,

public static void initAppointmentReservedDialog(final Activity activity){

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(activity.getString(R.string.appointment_reserved_dialog)).setCancelable(false).setPositiveButton(activity.getString(R.string.ok_button_dialog), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent nextScreen = new Intent(activity, MainOptionsActivity.class);
            activity.startActivity(nextScreen);
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

I get the following fatal exception in my log,

07-18 10:59:34.882: E/AndroidRuntime(4885): FATAL EXCEPTION: AsyncTask #2
07-18 10:59:34.882: E/AndroidRuntime(4885): java.lang.RuntimeException: An error occured while executing doInBackground()
07-18 10:59:34.882: E/AndroidRuntime(4885):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at java.lang.Thread.run(Thread.java:856)
07-18 10:59:34.882: E/AndroidRuntime(4885): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
07-18 10:59:34.882: E/AndroidRuntime(4885):     at android.os.Handler.<init>(Handler.java:121)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at android.app.Dialog.<init>(Dialog.java:107)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at android.app.AlertDialog.<init>(AlertDialog.java:114)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at android.app.AlertDialog$Builder.create(AlertDialog.java:913)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at org.digitalhealthagency.elaj.util.Dialogs.initAppointmentReservedDialog(Dialogs.java:277)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at org.digitalhealthagency.elaj.webservice.WebServiceResponse.appointmentReservation(WebServiceResponse.java:288)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at org.digitalhealthagency.elaj.gui.AppointmentConfirmationActivity$ReserveAppointmentTask.doInBackground(AppointmentConfirmationActivity.java:182)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at org.digitalhealthagency.elaj.gui.AppointmentConfirmationActivity$ReserveAppointmentTask.doInBackground(AppointmentConfirmationActivity.java:1)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
07-18 10:59:34.882: E/AndroidRuntime(4885):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-18 10:59:34.882: E/AndroidRuntime(4885):     ... 4 more

I would appreciate any help.

  • 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-07T19:25:35+00:00Added an answer on June 7, 2026 at 7:25 pm

    Reason as @PareshMayani said: You can’t update UI while doing inside doInBackground(). Yes you can but for that you have to include either runOnUiThread() or use onPostExecute()

    I would suggest such changes to update UI after the process

    private class ReserveAppointmentTask extends AsyncTask<Void, Void, Integer>{
    
        @Override
        protected void onPreExecute() {
            showDialog(RESERVING_PROGRESS_DIALOG);
        }
        @Override
        protected Integer doInBackground(Void... params) {        
            return WebServiceResponse.appointmentReservation(AppointmentConfirmationActivity.this, appointmentObj);            
        }
        @Override
        protected void onPostExecute(Integer response) {
            removeDialog(RESERVING_PROGRESS_DIALOG);
            if(response == RESPONSES.SUCCESSFULL){
    
                Dialogs.initAppointmentReservedDialog(activity);                            
            }
        }
    }
    

    now change your method appointmentReservation() like this

    public static int appointmentReservation(AppointmentConfirmationActivity activity, Appointment appointmentObj){
            SetAppointmentResponse setAppointmentResponse = SetAppointmentResponse.extractJSONResponse(response);
            return setAppointmentResponse.checkResponse();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that extends AsyncTask. In the doInBackground() method, I connect to
In my application I have two threads (I'm using AsyncTask class). in doInBackground() method
I have a class that extends AsyncTask , which fetches the gps cordinates from
I have an Activity class which has an attribute that references an AsyncTask instance
I have the following asynctask class which is not inside the activity. In the
I have an Activity Class with an inner protected class that extends AsyncTask. I
I have a nested inner class that extends AsyncTask to run a db query
I have an Android app that is crashing with the following error. Caused by:
I have a few things that need to be done asynchronously during my application's
I have an application that runs an activity with a service in a separate

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.