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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:13:35+00:00 2026-06-14T16:13:35+00:00

I’ve been trying to program an android that takes allows the user to pull

  • 0

I’ve been trying to program an android that takes allows the user to pull an image off the internet. After publishing this app, i was told by someone, that i need AsyncTask to allow me to use networking commands. Ive been studying the AsycTask page on Android Developers website (developer.android.com/reference/android/os/AsyncTask.html). This has me completely lost. I have no idea where i need to place this code. Here is my original code that is currently working until published. How can I implement the AsyncTask in here?

CODE:

public void firstbutton(View view) 
    {
        InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        EditText editText = (EditText)findViewById(R.id.editText1);
        inputMgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);

        EditText idnumber=(EditText)findViewById(R.id.editText1);
        String idnumber2= idnumber.getText().toString();
        int i = Integer.parseInt(editText.getText().toString());
        idnum=i;
        setContentView(R.layout.viewer);
        Context context = view.getContext();
        Drawable image = ImageOperations(context, "HIDDEN FOR PRIVACY"+idnumber2);
        ImageView icon = new ImageView(context);
        icon = (ImageView)findViewById(R.id.imageView1);
        icon.setImageDrawable(image);
};


public Drawable ImageOperations(Context ctx, String url) {
    try {
        InputStream is = (InputStream) this.fetch(url);
        Drawable d = Drawable.createFromStream(is, "src");
        return d;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

public Object fetch(String address) throws MalformedURLException,IOException
{
URL url = new URL(address);
Object content = url.getContent();
return content;
}

LOGCAT FOR TWADDINGTON

11-21 20:02:30.987: E/AndroidRuntime(343): java.lang.RuntimeException: An error occured while executing doInBackground()
11-21 20:02:30.987: E/AndroidRuntime(343):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
11-21 20:02:30.987: E/AndroidRuntime(343):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
11-21 20:02:30.987: E/AndroidRuntime(343):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
11-21 20:02:30.987: E/AndroidRuntime(343):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
11-21 20:02:30.987: E/AndroidRuntime(343):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-21 20:02:30.987: E/AndroidRuntime(343):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
11-21 20:02:30.987: E/AndroidRuntime(343):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
11-21 20:02:30.987: E/AndroidRuntime(343):  at java.lang.Thread.run(Thread.java:1096)
11-21 20:02:30.987: E/AndroidRuntime(343): Caused by: java.lang.ClassCastException: [Ljava.lang.Object;
11-21 20:02:30.987: E/AndroidRuntime(343):  at com.phil.avatarview.AvatarViewActivity$FetchImageAsyncTask.doInBackground(AvatarViewActivity.java:1)
11-21 20:02:30.987: E/AndroidRuntime(343):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
11-21 20:02:30.987: E/AndroidRuntime(343):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-21 20:02:30.987: E/AndroidRuntime(343):  ... 4 more
11-21 20:02:31.330: I/Process(61): Sending signal. PID: 343 SIG: 3
  • 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-14T16:13:36+00:00Added an answer on June 14, 2026 at 4:13 pm

    Something like this should get you started:

    /** A custom AsyncTask for downloading images in the background. */
    private static class FetchImageAsyncTask extends AsyncTask<Void, Void, Drawable> {
        private final String mUrl;
        private final ImageView mImageView;
    
        public FetchImageAsyncTask(ImageView view, String url) {
            mUrl = url;
            mImageView = view;
        }
    
        @Override
        protected Drawable doInBackground(Void... params) {
            // This aptly named method will run on a background Thread. This
            // means your user interface will not be interrupted while the
            // image is downloaded.
    
            try {
                URL url = new URL(mUrl);
    
                // Instead of URL#getContent() you might consider using the
                // DefaultHttpClient class.
                return Drawable.createFromStream(
                        (InputStream) url.getContent(), "src");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        @Override
        protected void onPostExecute(Drawable result) {
            // The result of doInBackground will be passed to this method, which
            // is run on the UI Thread. This is important because you cannot
            // update an ImageView with a new image from a background Thread.
            if (result != null) {
                mImageView.setImageDrawable(result);
            }
        }
    }
    
    public void firstbutton(View view) {
        InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        EditText editText = (EditText)findViewById(R.id.editText1);
        inputMgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
    
        EditText idnumber=(EditText)findViewById(R.id.editText1);
        String idnumber2= idnumber.getText().toString();
        int i = Integer.parseInt(editText.getText().toString());
        idnum=i;
        setContentView(R.layout.viewer);
        Context context = view.getContext();
    
        // Get your image view
        ImageView iconView = (ImageView) findViewById(R.id.imageView1);
    
        // Create a new background task
        FetchImageAsyncTask task = new FetchImageAsyncTask(iconView, "YOUR_URL_HERE");
    
        // Start the background task
        task.execute();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace

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.