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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:50:49+00:00 2026-06-18T06:50:49+00:00

In my asyncTask doInBackground() method I want to handle exception by making a toast.

  • 0

In my asyncTask doInBackground() method I want to handle exception by making a toast. But I am unable to do so, and this is exception I get. Why is that?
P.S. I can do it in onPreExecute() and onPostExecute().

02-04 09:43:45.190: E/AndroidRuntime(19308): FATAL EXCEPTION: AsyncTask #1
02-04 09:43:45.190: E/AndroidRuntime(19308): java.lang.RuntimeException: An error     occured while executing doInBackground()
02-04 09:43:45.190: E/AndroidRuntime(19308):    at android.os.AsyncTask$3.done(AsyncTask.java:278)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at java.lang.Thread.run(Thread.java:856)
02-04 09:43:45.190: E/AndroidRuntime(19308): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
02-04 09:43:45.190: E/AndroidRuntime(19308):    at android.os.Handler.<init>(Handler.java:121)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at android.widget.Toast$TN.<init>(Toast.java:317)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at android.widget.Toast.<init>(Toast.java:91)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at android.widget.Toast.makeText(Toast.java:233)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at com.xxx.MenuActivity$ImageCount.setView(MenuActivity.java:208)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at com.xxx.StringAsyncRetriever.getData(StringAsyncRetriever.java:101)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at com.xxx.StringAsyncRetriever.getData(StringAsyncRetriever.java:95)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at com.xxx.StringAsyncRetriever.doInBackground(StringAsyncRetriever.java:44)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at com.xxx.StringAsyncRetriever.doInBackground(StringAsyncRetriever.java:1)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
02-04 09:43:45.190: E/AndroidRuntime(19308):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  • 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-18T06:50:50+00:00Added an answer on June 18, 2026 at 6:50 am

    You cannot make a ui action inside doInBackground, so in case of exception return a value that can be checked in the onPostExecute .. based on this value show your toast

    • 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
I don't want to pass any arguments to doInBackground method of the AsyncTask. So
I am learning AsyncTask,I tried to print Toast message inside doInBackground method,is it possible
I created an asynctask and in its doInBackground() method i started a thread like
I have an AsyncTask and on the background I want to start Service that
All I want to do is use AsyncTask to do a http request. This
Hi All I want to pass a Variables to AsyncTask I've This Variables private
What I want to do is run a method that will play a random
I have a AsyncTask in which an activity is launched during the doInBackground method:
In Android app i want to return JSONObject from doInBackground() method to onPostExecute() method.

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.