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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:56:01+00:00 2026-06-10T23:56:01+00:00

I use Google Chart API to build chart’s in my app. In my case

  • 0

I use Google Chart API to build chart’s in my app.

In my case I need to download image on each chart. I use AsyncTask for this.

To monitor download procces I use Progress dialog. But got a errors in this class of AsyncTask.

execute of AsyncTask:

new loadChart(ChartAct.this,img).execute();

and code of AsyncTask:

public class loadChart extends AsyncTask<Void, Void, Void> {
    private ImageView img;
    private Context con;
    private ProgressDialog dialog;

    public loadChart(Context context, ImageView img1) {
        this.img = img1;
        this.con = context;
    }

    @Override
    protected void onPreExecute() {
        dialog = ProgressDialog.show(con, "Connecting:",
                "Loading. Please wait...", true);
        super.onPreExecute();
    }

    @Override
    protected Void doInBackground(Void... params) {
        final Bitmap bitmap = DownloadImage();
        img.setImageBitmap(bitmap);
        return null;
    }

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

    private static InputStream OpenHttpConnection(String urlString)
            throws IOException {

        Log.d("palval", "OpenHttpConnection");
        InputStream in = null;
        int response = -1;

        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();

        if (!(conn instanceof HttpURLConnection))
            throw new IOException("Not an HTTP connection");

        try {
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();

            response = httpConn.getResponseCode();

            if (response == HttpURLConnection.HTTP_OK) {
                in = httpConn.getInputStream();
            }

            String res = Integer.toString(response);
        } catch (Exception ex) {
            throw new IOException("Error connecting");
        }
        return in;
    }

    public static Bitmap DownloadImage() {
        Log.d("palval", "DownloadImage");
        Bitmap bitmap = null;
        InputStream in = null;
        try {

            in = OpenHttpConnection("https://chart.googleapis.com/chart?chs=440x220&chd=t:60,40&cht=p3&chl=Hello|World");
            bitmap = BitmapFactory.decodeStream(in);
            in.close();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        return bitmap;
    }

}

errors:

09-06 18:35:35.574: E/AndroidRuntime(2502): FATAL EXCEPTION: AsyncTask #1
09-06 18:35:35.574: E/AndroidRuntime(2502): java.lang.RuntimeException: An error occured while executing doInBackground()
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at java.lang.Thread.run(Thread.java:864)
09-06 18:35:35.574: E/AndroidRuntime(2502): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4132)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:723)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.view.View.requestLayout(View.java:12957)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.view.View.requestLayout(View.java:12957)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.view.View.requestLayout(View.java:12957)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.view.View.requestLayout(View.java:12957)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.view.View.requestLayout(View.java:12957)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.widget.ImageView.setImageDrawable(ImageView.java:362)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.widget.ImageView.setImageBitmap(ImageView.java:377)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at com.example.headache.loadChart.doInBackground(loadChart.java:37)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at com.example.headache.loadChart.doInBackground(loadChart.java:1)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
09-06 18:35:35.574: E/AndroidRuntime(2502):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-06 18:35:35.574: E/AndroidRuntime(2502):     ... 5 more
09-06 18:35:36.055: E/WindowManager(2502): Activity com.example.headache.ChartAct has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40dd3b28 that was originally added here
09-06 18:35:36.055: E/WindowManager(2502): android.view.WindowLeaked: Activity com.example.headache.ChartAct has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40dd3b28 that was originally added here
09-06 18:35:36.055: E/WindowManager(2502):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:352)
09-06 18:35:36.055: E/WindowManager(2502):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:373)
09-06 18:35:36.055: E/WindowManager(2502):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:321)
09-06 18:35:36.055: E/WindowManager(2502):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:152)
09-06 18:35:36.055: E/WindowManager(2502):  at android.view.Window$LocalWindowManager.addView(Window.java:541)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.Dialog.show(Dialog.java:301)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.ProgressDialog.show(ProgressDialog.java:116)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.ProgressDialog.show(ProgressDialog.java:99)
09-06 18:35:36.055: E/WindowManager(2502):  at com.example.headache.loadChart.onPreExecute(loadChart.java:29)
09-06 18:35:36.055: E/WindowManager(2502):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
09-06 18:35:36.055: E/WindowManager(2502):  at android.os.AsyncTask.execute(AsyncTask.java:511)
09-06 18:35:36.055: E/WindowManager(2502):  at com.example.headache.ChartAct.onCreate(ChartAct.java:31)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.Activity.performCreate(Activity.java:4531)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.ActivityThread.access$600(ActivityThread.java:139)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
09-06 18:35:36.055: E/WindowManager(2502):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 18:35:36.055: E/WindowManager(2502):  at android.os.Looper.loop(Looper.java:154)
09-06 18:35:36.055: E/WindowManager(2502):  at android.app.ActivityThread.main(ActivityThread.java:4945)
09-06 18:35:36.055: E/WindowManager(2502):  at java.lang.reflect.Method.invokeNative(Native Method)
09-06 18:35:36.055: E/WindowManager(2502):  at java.lang.reflect.Method.invoke(Method.java:511)
09-06 18:35:36.055: E/WindowManager(2502):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-06 18:35:36.055: E/WindowManager(2502):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-06 18:35:36.055: E/WindowManager(2502):  at dalvik.system.NativeStart.main(Native Method)
  • 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-10T23:56:03+00:00Added an answer on June 10, 2026 at 11:56 pm

    You cannot set an image in doInBackground() make it return a bitmap and set it in the onPostExecute()

    public class loadChart extends AsyncTask<Void, Void, Bitmap> {
        private ImageView img;
        private Context con;
        private ProgressDialog dialog;
    
        public loadChart(Context context, ImageView img1) {
            this.img = img1;
            this.con = context;
        }
    
        @Override
        protected void onPreExecute() {
            dialog = ProgressDialog.show(con, "Connecting:",
                    "Loading. Please wait...", true);
            super.onPreExecute();
        }
    
        @Override
        protected Bitmap doInBackground(Void... params) {
            final Bitmap bitmap = DownloadImage();
            return bitmap;
        }
    
        @Override
        protected void onPostExecute(Bitmap result) {
            dialog.dismiss();
            img.setImageBitmap(result);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see this link to use google chart api for putting multiple line charts
I am using a google chart API in this how can i use this
I am trying to use the google chart tools (from the visualization api; not
I use Google Visualization API to plot Line Chart. Here are the codes: google.load(visualization,
I want to use Google Chart API using javascript. (I don't want to use
Can anyone tell me if they know how to use the Google Chart API
Is Google Chart API free to use? If so, where can I find its
I am trying to use the Google Charts API to create a chart that
Is there a way to use the Google Chart Javascript API to center bars
I need to create QrCode images (with Google Chart API) that has special QrCode

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.