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

  • Home
  • SEARCH
  • 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 6674179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:42:55+00:00 2026-05-26T03:42:55+00:00

private void Load() { new pbar().execute(); //dialog = ProgressDialog.show(Display.this, , Loading. Please wait…, true);

  • 0
private void Load()
{
    new pbar().execute();
    //dialog = ProgressDialog.show(Display.this, "", "Loading. Please wait...", true);
    success = faHelper.SourceDownload(Url);
    displaystuff();
    //dialog.dismiss();
}

private class pbar extends AsyncTask<Void, Void, Void> 
{
   protected Void doInBackground(Void...unused) 
   {
       dialog = ProgressDialog.show(Display.this, "", "Loading. Please wait...", true);
       while (success == 0) {}
       dialog.dismiss();
       return null;
   }
}

i have this code that throws an error. i need a pbar that shows till success is = something other than 0.

10-06 16:34:52.802: ERROR/AndroidRuntime(6055): FATAL EXCEPTION: AsyncTask #1
10-06 16:34:52.802: ERROR/AndroidRuntime(6055): java.lang.RuntimeException: An error occured while executing doInBackground()
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at java.lang.Thread.run(Thread.java:1027)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.os.Handler.<init>(Handler.java:121)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.app.Dialog.<init>(Dialog.java:145)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.app.AlertDialog.<init>(AlertDialog.java:63)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.app.ProgressDialog.<init>(ProgressDialog.java:80)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.app.ProgressDialog.<init>(ProgressDialog.java:76)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.app.ProgressDialog.show(ProgressDialog.java:101)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.app.ProgressDialog.show(ProgressDialog.java:90)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at com.Testapp3.Display$pbar.doInBackground(Display.java:132)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at com.Testapp3.Display$pbar.doInBackground(Display.java:1)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
10-06 16:34:52.802: ERROR/AndroidRuntime(6055):     ... 4 more

that is the logcat im getting. i know this is something that is super simple, but it is escaping me. any advice will be appreciated. thx

updated code:

private void Load()
{
    new pbar().execute();
    success = faHelper.SourceDownload(Url);
    displaystuff();
}

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

    @Override
    protected void onPreExecute() 
    {
        dialog = ProgressDialog.show(Display.this, "", "Loading. Please wait...", true);
    }

    @Override
    protected void onPostExecute(Void result) 
    {
        dialog.dismiss();
        return;
    }

    protected Void doInBackground(Void...unused) 
    {
        while (success == 0) {}
        return null;
    }
}

the error went away tho, but you never see the dialog.

  • 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-05-26T03:42:56+00:00Added an answer on May 26, 2026 at 3:42 am

    The problem you are experiencing is because you are executing the thread which barely gets a chance to start befor it finishes. Then after it has died you are dowloading with your helper. You need to move the download code into the doInBackground method of the AsyncTask.

    This is more along the lines of what is necessary:

    private void Load()
    {
        new pbar().execute(url);
    }
    
    private class pbar extends AsyncTask<Url, Void, Long> 
    {
        private final String message = "Loading. Please wait...";
        private int success=0;
    
        @Override
        protected void onPreExecute() 
        {
            dialog = ProgressDialog.show(Display.this, "", message, true);
        }
    
        @Override
        protected void onPostExecute(Long result) 
        {
            dialog.dismiss();
            Display.displaystuff();
        }
    
        protected Long doInBackground(Url... urls) 
        {
            return faHelper.SourceDownload(urls[0]);
        }
    }
    

    For more information please check out the AsyncTask developer docs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

private void BindCountry() { XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath(countries.xml)); foreach (XmlNode node in
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.UserClosing) { if (MessageBox.Show(this,
partial class Form1 { //hidden private void InitializeComponent() { this.picture = new System.Windows.Forms.PictureBox(); //hidden
. private void Form1_Load(object sender, EventArgs e) { List<CaclulatedData> tests = new List<CaclulatedData> {
private void activateRecords(long[] stuff) { ... api.activateRecords(Arrays.asList(specIdsToActivate)); } Shouldn't this call to Arrays.asList return
private void EnsureCurrentlyValid() { //I'm valid if IDataErrorInfo.this[] returns null for every property var
private void validateXML(DOMSource source) throws Exception { URL schemaFile = new URL(http://www.csc.liv.ac.uk/~valli/modules.xsd); SchemaFactory schemaFactory
I have this code private void writeReport(IReport report, string reportName) { string reportString =
I'am new with C#. How works in C# functions? My try: private void Form1_Load(object
private void screensaverWindow_Load(object sender, System.EventArgs e) { this.BringToFront(); this.Focus(); this.KeyPreview = true; this.KeyDown +=

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.