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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:24:12+00:00 2026-05-26T20:24:12+00:00

I am getting an issue to run the below code.The code gives no error

  • 0

I am getting an issue to run the below code.The code gives no error but not giving the expected output. Any suggestions or solution will be highly appreciated.Thanx in advance.

Here’s my xml file:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/readWebpage"
            android:text="Load Webpage"
            android:onClick="readWebpage"/>

    <TextView android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/textView1"
              android:text="Example Text"
              android:layout_gravity="center_horizontal"/>

</LinearLayout>

and here’s my java file:-

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class LoadWebpageAsyncTask extends Activity {

    TextView tv;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        tv = (TextView)findViewById(R.id.textView1);

    }
    public class DownloadWebpageTask extends AsyncTask<String,Void,String>{

        @Override
        protected String doInBackground(String... urls) {
            // TODO Auto-generated method stub

            String response = "";
            for(String url:urls){
                DefaultHttpClient client = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(url);
                try{
                    HttpResponse execute = client.execute(httpGet);
                    BufferedReader br = new BufferedReader(new 
                            InputStreamReader(execute.getEntity().getContent()));
                    String s="";
                    while((s = br.readLine()) != null){

                        response += s;
                    }
                }
                catch(Exception e){
                    e.printStackTrace();
                }
            }
            return response;
        }


        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub

            tv.setText(result);
        }

    }

        public void readWebpage(View view){ 
            DownloadWebpageTask task = new DownloadWebpageTask();
            task.execute(new String[]{"http://www.google.com"});

            }
}
  • 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-26T20:24:13+00:00Added an answer on May 26, 2026 at 8:24 pm

    It looks like you are missing setContentView(R.layout.<...>); (tv will be null) in your onCreate() method and never run your task (so you don’t get NullPointerException when setting text on tv):

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView)findViewById(R.id.textView1);
        readWebpage(null); //you never use argument anyway
    }
    

    edit riha’s answer is also true, since the way you use it is for (String[] url:urls), not for (String url:urls)

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

Sidebar

Related Questions

I am getting the below error below when I run my custom yiic command
I'm having an issue getting some code to work. Is there a way to
We are getting a weird issue on which we are not sure what exactly
I'm getting the error below when I try and access SSRS on SQL Server
I am using the code below to set my two NSArray ivars: The issue
I'm having an issue getting surefire to run Junit4 tests. This same issue was
I'm getting an issue with the F# powerpack quotation evaluation. open Microsoft.FSharp.Linq.QuotationEvaluation let print
I'm having an issue getting a LINQ query to work. I have this XML:
I'm having an issue getting files loaded into an app called GCS, by dragging
I'm having an issue getting this CSS for a sprite sheet to work on

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.