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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:03:55+00:00 2026-06-14T03:03:55+00:00

I am having this exception: java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:278)

  • 0

I am having this exception:

java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:278)
        at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:121)
        at android.widget.Toast$TN.<init>(Toast.java:347)
        at android.widget.Toast.<init>(Toast.java:93)
        at android.widget.Toast.makeText(Toast.java:235)
        at com.problemio.TopicActivity$DownloadWebPageTask.doInBackground(TopicActivity.java:440)
        at com.problemio.TopicActivity$DownloadWebPageTask.doInBackground(TopicActivity.java:1)
        at android.os.AsyncTask$2.call(AsyncTask.java:264)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        ... 5 more
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
        at android.os.Handler.<init>(Handler.java:121)
        at android.widget.Toast$TN.<init>(Toast.java:347)
        at android.widget.Toast.<init>(Toast.java:93)
        at android.widget.Toast.makeText(Toast.java:235)
        at com.problemio.TopicActivity$DownloadWebPageTask.doInBackground(TopicActivity.java:440)
        at com.problemio.TopicActivity$DownloadWebPageTask.doInBackground(TopicActivity.java:1)
        at android.os.AsyncTask$2.call(AsyncTask.java:264)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
        at java.util.concurrent.FutureTask.run(FutureTask.java:137)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
        at java.lang.Thread.run(Thread.java:856)

With this code:

Dialog dialog;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
 ....

dialog = new Dialog(this);
    Button submit = (Button)findViewById(R.id.submit_comment);   
    submit.setOnClickListener(new Button.OnClickListener() 
    {  
       public void onClick(View v) 
       {
          dialog.setContentView(R.layout.please_wait);
          dialog.setTitle("Submitting Your Comment");

          TextView text = (TextView) dialog.findViewById(R.id.please_wait_text);
          text.setText("Please wait while your comment is processed... ");
          dialog.show(); //this will show dialog 

          String c = comment.getText().toString(); 

          if ( c == null || c.length() == 0 )
          {
                try {
                    dialog.dismiss();
                } catch (Exception ee) {
                    // nothing
                }
          }
          else
          {             
              ...  
          }
       }
    });


    // Go to the database and display a list of problems
sendFeedback( problem_id , recent_topic_id );   
}       

public void sendFeedback(String problem_id , String recent_topic_id) 
{  

    String[] params = new String[] 
            { "url", problem_id , recent_topic_id };

    DownloadWebPageTask task = new DownloadWebPageTask();
    task.execute(params);        
}       

public class DownloadWebPageTask extends AsyncTask<String, Void, String> 
{
    @Override
    protected String doInBackground(String... theParams) 
    {
        String myUrl = theParams[0];
        final String problem_id = theParams[1];
        final String solution_section = theParams[2];

        String charset = "UTF-8";           
        String response = null;

        try 
        {                           
            String query = String.format("problem_id=%s&solution_section=%s", 
                     URLEncoder.encode( problem_id, charset),
                     URLEncoder.encode( solution_section, charset));

            final URL url = new URL( myUrl + "?" + query );

            final HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setDoOutput(true); 
            conn.setRequestMethod("POST");

            conn.setDoOutput(true);
            conn.setUseCaches(false);

            conn.connect();

            final InputStream is = conn.getInputStream();
            final byte[] buffer = new byte[8196];
            int readCount;
            final StringBuilder builder = new StringBuilder();
            while ((readCount = is.read(buffer)) > -1) 
            {
                builder.append(new String(buffer, 0, readCount));
            }

            response = builder.toString();      
        } 
        catch (Exception e) 
        {
            // What should I do here?           
        }

        return response;
    }

    @Override
    protected void onPostExecute(String result) 
    {       
        if ( result == null )
        {
            try {
                dialog.dismiss();
            } catch (Exception ee) {
                // nothing
            }                               
        }
        else
        if ( result.equals("no_suggested_solution_id") || result.equals("no_topic_id" ) )
        {               
            try {
                dialog.dismiss();
            } catch (Exception ee) {
                // nothing
            }                               
        }
        else
        { 
            if ( result.length() == 0 )
            {
                discussion.clear();

                DiscussionMessage message = new DiscussionMessage ( );
                message.setMessage("This section is empty.");

                discussion.add( message );                  
            }
            else
            {
                try
                {   
                    JSONArray obj = new JSONArray(result);

                    if ( obj != null )
                    {
                        discussion.clear();

                        TextView topic_instructions = (TextView) findViewById(R.id.topic_instructions);

                    } 
                    adapter.notifyDataSetChanged();                     
                }                   
                catch ( Exception e )
                {
                    e.printStackTrace();
                }
            }

            adapter.notifyDataSetChanged();                     
        }
    }    

Any idea what I am doing incorrectly with the dialog to have this exception?

Thanks!

  • 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-14T03:03:56+00:00Added an answer on June 14, 2026 at 3:03 am

    I’d have initiated the dialog in the “onPreExecute()”

     protected void onPostExecute(Long result) {
         dialog = new Dialog(YourActivityName.this);
         //your initiation
         dialog.show()
     }
    

    And inside the doInBackground() i’d have returned a null if there was an exception thrown.

    And try to dismiss the dialog at the beginning of the onPostExecute()

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

    If that doesn’t help then try moving the asynctask to a separate class, and not an inner class of the activity, it usually works for me just fine when I write the asynctask in a different class.

    I see that in your code you are calling “sendFeedback()” not inside the onClick method.

    You are calling dismiss() on a dialog that has started after the asynctask started running, maybe it could be the problem?

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

Sidebar

Related Questions

I'm having a problem where I receive this error: Exception in thread main java.lang.NullPointerException
Having this code I get the error: Exception in thread AWT-EventQueue-0 java.lang.NoClassDefFoundError: org/apache/axis/EngineConfiguration I
I'm having this error in eclipes java.lang.UnsupportedClassVersionError: Bad version number in .class file .
I'm having this error page in Django. Exception Type: IndexError Exception Value: list index
I am having problems executing a AlertDialog on a postexecute(). Throws this exception Caused
I'm having this exception, @6agjdofnm Internal Server Error (500) for request GET / Oops:
What can this exception mean exactly? java.lang.NullPointerException: WriteText method cannot write null text at
Despite this project having worked for me for a while, I'm now getting an
Having this problem with my android app I struggled with this for some time
I am having this annoying problem of loading DB2 driver from a JAVA application

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.