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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:26:00+00:00 2026-06-15T17:26:00+00:00

In my application one button and one ImageView is there. After clicking on button

  • 0

In my application one button and one ImageView is there. After clicking on button it get the photo from server and display on inmageView. At the time of getting photo from server it show progress bar.

This application able to get photo from server but not able to display on imageview.

code (for button):

@Override
public void onClick(View v) {
    switch (v.getId()) {
         case R.id.buttonFetchPhoto:
             new BackgroundTask().execute("Main");
             break;
    }
}

code(for progress bar)

class BackgroundTask extends AsyncTask<String , Integer, Void>
{
    @Override
    protected void onPreExecute()
    {
        bar = new ProgressDialog(activity.this);
        bar.setMessage("Processing..");
        bar.setIndeterminate(true);
        bar.show();

    } 
    @Override
    protected Void doInBackground(String... params) 
    {   
        // Code to get Photo Byte Array from server

        Bitmap bm = BitmapFactory.decodeByteArray(photoByteArray, 0,photoByteArray.length);
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);

        imageViewGetPhoto.setImageBitmap(bm); //imageViewGetPhoto is define in activity class
        }

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

I am getting error because of “imageViewGetPhoto.setImageBitmap(bm)“

I think this is because “imageViewGetPhoto” is defined into the layout class which is main thread and this thread not able to synchronize with main thread.

How I get the data into Main thread which is retrieved by other thread.

Or how I access objects into other thread which is defined in main layout.

Error:

FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)          
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original      thread that created a view hierarchy can touch its views.
at android.view.ViewRoot.checkThread(ViewRoot.java:3020)
at android.view.ViewRoot.requestLayout(ViewRoot.java:634)
at android.view.View.requestLayout(View.java:8267)
at android.view.View.requestLayout(View.java:8267)
at android.view.View.requestLayout(View.java:8267)
at android.view.View.requestLayout(View.java:8267)
at android.widget.ScrollView.requestLayout(ScrollView.java:1580)
at android.view.View.requestLayout(View.java:8267)
at android.widget.TableLayout.requestLayout(TableLayout.java:226)
at android.view.View.requestLayout(View.java:8267)
at android.view.View.requestLayout(View.java:8267)
at android.widget.TableLayout.requestLayout(TableLayout.java:226)
at android.view.View.requestLayout(View.java:8267)
at android.view.View.requestLayout(View.java:8267)
at android.widget.ImageView.setImageDrawable(ImageView.java:322)
at android.widget.ImageView.setImageBitmap(ImageView.java:336)
at com.pixel.potholelocator.PohholeLocatorActivity$BackgroundTask.doInBackground(PohholeLocatorActivity.java:295)
at com.pixel.potholelocator.PohholeLocatorActivity$BackgroundTask.doInBackground(PohholeLocatorActivity.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
  • 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-15T17:26:01+00:00Added an answer on June 15, 2026 at 5:26 pm

    Write these 3 lines in

    @Override
        protected void onPostExecute(Void result) 
        { 
            bar.dismiss();
            DisplayMetrics dm = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(dm);
    
            imageViewGetPhoto.setImageBitmap(bm); 
    
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application one frame is there on which one button is there. If
In my application, there is one button in the navigation bar. I want it
In my application is that there is one button in bottom toolbar and when
I have a application to capture photo which will display on ImageView (and do
My application has one button. If you click that button then it will display
My application adds a photo from your gallery to an ImageView just fine, but
I implemented one application in that application one button is there. if you click
In Application i have two buttons in which one button is used as a
My application is viewbased application in which I have one button. On click of
In my application i want send a email to one account.in one button click

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.