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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:39:10+00:00 2026-05-19T02:39:10+00:00

i’m new to android development and i’m playing around with json data. I managed

  • 0

i’m new to android development and i’m playing around with json data. I managed to get the parsing to work. I want to show a ProgressDialog and i read that i need to use AsyncTask that. But for some reason i get a force close as soon as i put the same working code inside doInBackground() eventhough eclipse says everything is fine.

Here is the source code:

public class HomeActivity extends Activity {


  public class BackgroundAsyncTask extends AsyncTask<Void, Integer, Void> {

      ProgressDialog dialog = new ProgressDialog (HomeActivity.this);


      @Override
      protected void onPreExecute() {
        dialog.setMessage("Loading...please wait");
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        dialog.show();
      }

      protected void onPostExecute() {
             dialog.dismiss();
          }

      @Override
      protected Void doInBackground(Void... params) {         
            try {
                URL json = new URL("http://www.corps-marchia.de/jsontest.php");
                URLConnection tc = json.openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));

                String line;
                while ((line = in.readLine()) != null) {
                    JSONArray ja = new JSONArray(line);
                    JSONObject jo = (JSONObject) ja.get(0);
                    TextView txtView = (TextView)findViewById(R.id.TextView01);
                    txtView.setText(jo.getString("text"));
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }

       return null;
       }
     }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        new BackgroundAsyncTask().execute();
    }

}

Here is the error log:

01-08 12:33:48.225: ERROR/AndroidRuntime(815): FATAL EXCEPTION: AsyncTask #1
01-08 12:33:48.225: ERROR/AndroidRuntime(815): java.lang.RuntimeException: An error occured while executing doInBackground()
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at java.lang.Thread.run(Thread.java:1019)
01-08 12:33:48.225: ERROR/AndroidRuntime(815): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.view.ViewRoot.checkThread(ViewRoot.java:2932)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.view.ViewRoot.requestLayout(ViewRoot.java:629)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.view.View.requestLayout(View.java:8267)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.view.View.requestLayout(View.java:8267)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.view.View.requestLayout(View.java:8267)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.view.View.requestLayout(View.java:8267)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.view.View.requestLayout(View.java:8267)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.widget.TextView.checkForRelayout(TextView.java:5521)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.widget.TextView.setText(TextView.java:2724)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.widget.TextView.setText(TextView.java:2592)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.widget.TextView.setText(TextView.java:2567)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at net.ajzele.demo.andy1.HomeActivity$BackgroundAsyncTask.doInBackground(HomeActivity.java:52)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at net.ajzele.demo.andy1.HomeActivity$BackgroundAsyncTask.doInBackground(HomeActivity.java:1)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-08 12:33:48.225: ERROR/AndroidRuntime(815):     ... 4 more
01-08 12:33:51.605: ERROR/WindowManager(815): Activity net.ajzele.demo.andy1.HomeActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4051d0c0 that was originally added here
01-08 12:33:51.605: ERROR/WindowManager(815): android.view.WindowLeaked: Activity net.ajzele.demo.andy1.HomeActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4051d0c0 that was originally added here
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.view.ViewRoot.<init>(ViewRoot.java:258)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.app.Dialog.show(Dialog.java:241)
01-08 12:33:51.605: ERROR/WindowManager(815):     at net.ajzele.demo.andy1.HomeActivity$BackgroundAsyncTask.onPreExecute(HomeActivity.java:33)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.os.AsyncTask.execute(AsyncTask.java:391)
01-08 12:33:51.605: ERROR/WindowManager(815):     at net.ajzele.demo.andy1.HomeActivity.onCreate(HomeActivity.java:72)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.os.Looper.loop(Looper.java:123)
01-08 12:33:51.605: ERROR/WindowManager(815):     at android.app.ActivityThread.main(ActivityThread.java:3647)
01-08 12:33:51.605: ERROR/WindowManager(815):     at java.lang.reflect.Method.invokeNative(Native Method)
01-08 12:33:51.605: ERROR/WindowManager(815):     at java.lang.reflect.Method.invoke(Method.java:507)
01-08 12:33:51.605: ERROR/WindowManager(815):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-08 12:33:51.605: ERROR/WindowManager(815):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-08 12:33:51.605: ERROR/WindowManager(815):     at dalvik.system.NativeStart.main(Native Method)

Any hints? I hope you can help me out ive searched the net and didnt find any working solution…Thanks in advance

  • 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-19T02:39:10+00:00Added an answer on May 19, 2026 at 2:39 am

    Check the docs for AsyncTask. You can’t directly manipulate the UI from within doInBackground. In order to make UI updates, you need to call publishProgress. You will also need to change the signature of your AsyncTask to pass a String. So something like this:

    public class BackgroundAsyncTask extends AsyncTask<Void, String, Void> {
        TextView txtView = (TextView)findViewById(R.id.TextView01);
        ...
        protected void onProgressUpdate(String... message) {
            txtView.setText(message[0]);
        }
        ...
        @Override
        protected Void doInBackground(Void... params) {
             try {
                 URL json = new URL("http://www.corps-marchia.de/jsontest.php");
                 URLConnection tc = json.openConnection();
                 BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));
    
                 String line;
                 while ((line = in.readLine()) != null) {
                     JSONArray ja = new JSONArray(line);
                     JSONObject jo = (JSONObject) ja.get(0);
                     publishProgress(jo.getString("text"));
                 }
             } catch (MalformedURLException e) {
                 e.printStackTrace();
             } catch (IOException e) {
                 e.printStackTrace();
             } catch (JSONException e) {
                 e.printStackTrace();
             }
    
        return null;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have some data like this: 1 2 3 4 5 9 2 6
I've got a string that has curly quotes in it. I'd like to replace
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.