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

The Archive Base Latest Questions

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

i am aware that the error is occurring because im trying to put a

  • 0

i am aware that the error is occurring because im trying to put a network call on the main thread so i need to use a handler or asynctask

however i dont seem to be able to get it right

this is the code im trying to get to work

 try {
                // Create a URL for the desired page
                URL url = new URL("http://darkliteempire.gaming.multiplay.co.uk/testdownload.txt");


                // Read all the text returned by the server
                BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
                String str;
                while ((str = in.readLine()) != null) {
                    // str is one line of text; readLine() strips the newline character(s)

                    eventText.setText(str);
                    eventText.setText(in.readLine());
                }
                in.close();
            } catch (MalformedURLException e) {
                Toast.makeText(getBaseContext(), "MalformedURLException", Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                Toast.makeText(getBaseContext(), "IOException", Toast.LENGTH_LONG).show();
            }

and i want to call it when this button is clicked

public void onClick(View v) {

if (v.getId() == R.id.update) {
}
}

is anyone able to show me what i should wrap the first bit in and how to call it from the onClick

  • 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-15T23:14:02+00:00Added an answer on June 15, 2026 at 11:14 pm

    Something like

    public class TalkToServer extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
    
        @Override
        protected void onProgressUpdate(String... values) {
            super.onProgressUpdate(values);
    
        }
    
        @Override
        protected String doInBackground(String... params) {
        //do your work here
            return something;
        }
    
        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
               // do something with data here-display it or send to mainactivity
    }
    

    Do all heavy-lifting in doInBackground() and you can update the UI in the other 3 methods.

    Here is the documentation on AsyncTask

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

Sidebar

Related Questions

First of all, I'm well aware that this error is occur because I'm trying
Now I am aware that I probably need to use a ListBox and can
I wrote a custom error handler for my site and I'm aware that PHP
I'm aware that I could use something called std::vector , but I'm afraid it's
An application I'm writing needs to use .Net Remoting (I'm aware that WCF is
I'm getting this JS error while trying to use Ember routing: Uncaught TypeError: Object
I'm aware that I can use a table value parameter as another option and
I aware that this will be a less programming question, but still... How can
I am aware that I can set null like string val = null; But
I'm aware that this is possible with the os module's os.system(color) function, but this

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.