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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:31:14+00:00 2026-05-25T11:31:14+00:00

The code shown uses an AsyncTask class to call a blocking process so that

  • 0

The code shown uses an AsyncTask class to call a blocking process so that the UI is not blocked, and a progressbar is shown. The funny thing is that the onClick method works, but the KeyCode method doesn’t. Any suggestions please?


    // inside the onCreate method of the activity
    .....
        ttsymbol.setOnKeyListener(new OnKeyListener() 
            { 
                @Override 
                public boolean onKey(View v, int keyCode, KeyEvent event) { 
                        switch (keyCode)
                        {
                        case KeyEvent.KEYCODE_ENTER:
                            setProgressBarIndeterminateVisibility(true);
                            new myBGtask().execute(ttsymbol.getText().toString().trim());
                            return true;
                        } 
                        return false; 
                } 
            }
        ); 
        mainPanel.addView(ttsymbol);

        //GetData button
        final Button btnGetData = new Button(this);
        // configure the button adding onClick method 
        btnGetData.setText("Get Pivot Point");
        btnGetData.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        btnGetData.setGravity(Gravity.CENTER);
        btnGetData.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                setProgressBarIndeterminateVisibility(true);
                new myBGtask().execute(ttsymbol.getText().toString().trim());
            }
        });
        mainPanel.addView(btnGetData);
    .....

    private class myBGtask extends AsyncTask {
    private String spage;
    protected Long  doInBackground(String... URL) {
        String starget;
      try {
          starget =  URL[0];
          spage = CustomHttpClient.myHttpGet(starget);
      } catch (Exception e) {
          Toast.makeText(getBaseContext(), "failed to GET webpage", Toast.LENGTH_SHORT).show();
          e.printStackTrace();
      }
      return (long) 0;
    }
    protected void onProgressUpdate(Integer... progress) {

    }
    protected void onPostExecute(Long result) {
        String sresults;
        setProgressBarIndeterminateVisibility(false);
        sresults = scrape(spage);
        if (sresults.length() == 0 ) 
        {
            lblDATE.setTextColor( Color.BLACK);
            lblDATE.setText( "cannot find that!");
            return;
        }
        String s[] = sresults.split("\n");

        lblDATE.setText(s[0]);
        .....
    }
    }

error messages:


09-07 20:10:32.554: ERROR/AndroidRuntime(334): FATAL EXCEPTION: AsyncTask #1
09-07 20:10:32.554: ERROR/AndroidRuntime(334): java.lang.RuntimeException: An error occured while executing doInBackground()
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at java.lang.Thread.run(Thread.java:1019)
09-07 20:10:32.554: ERROR/AndroidRuntime(334): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at android.os.Handler.(Handler.java:121)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at android.widget.Toast.(Toast.java:68)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at android.widget.Toast.makeText(Toast.java:231)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at com.chrisdev.geturltry1.Chrisgeturltry1Activity$myBGtask.doInBackground(Chrisgeturltry1Activity.java:204)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at com.chrisdev.geturltry1.Chrisgeturltry1Activity$myBGtask.doInBackground(Chrisgeturltry1Activity.java:1)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
09-07 20:10:32.554: ERROR/AndroidRuntime(334):     ... 4 more
09-07 20:10:32.619: WARN/ActivityManager(69):   Force finishing activity com.chrisdev.geturltry1/.Chrisgeturltry1Activity
  • 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-25T11:31:15+00:00Added an answer on May 25, 2026 at 11:31 am

    You get an error because Toast.makeToast() is called from background thread. You can’t do it in doInBackground() instead return value from this method describing exception and show toast in onPostExecute() if you get this specific value.

    Apparently, code in try block fails in one case but not another. That’s different from problem with looper.prepare().

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

Sidebar

Related Questions

Background: I have a WPF UserControl (MainControl - not shown in code below) that
I have noticed that my geocoder is inconsistent in the code shown below because
I've got a program that worked until recently. The offending code is shown here:
The code I have looks like this (all uses of done shown): bool done
I have some code that uses dispatchEvent to simulate clicks and the same exact
I have some code that uses the Oracle function add_months to increment a Date
This question relates to recursion. Consider the program shown below (not my real code,
In the code shown below, I need to manipulate the time var in python
In the code shown below, how to get the values of multiselect box in
Okay, so I've got the following code shown below to create a dialog using

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.