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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:57:45+00:00 2026-06-14T19:57:45+00:00

I am trying to connect to an URL address in Android to get the

  • 0

I am trying to connect to an URL address in Android to get the HTML code. I am following this tutorial. I get an error when the readStream function is called. This is the error output in the log:

11-23 20:24:22.572: W/WindowManager(151): Failure taking screenshot for (246x437) to layer 21010
11-23 20:24:23.122: W/System.err(698): android.os.NetworkOnMainThreadException
11-23 20:24:23.133: W/System.err(698):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
11-23 20:24:23.133: W/System.err(698):  at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
11-23 20:24:23.133: W/System.err(698):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
11-23 20:24:23.133: W/System.err(698):  at java.net.InetAddress.getAllByName(InetAddress.java:214)
11-23 20:24:23.133: W/System.err(698):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
11-23 20:24:23.142: W/System.err(698):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
11-23 20:24:23.142: W/System.err(698):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
11-23 20:24:23.142: W/System.err(698):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
11-23 20:24:23.153: W/System.err(698):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
11-23 20:24:23.153: W/System.err(698):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
11-23 20:24:23.153: W/System.err(698):  at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:461)
11-23 20:24:23.153: W/System.err(698):  at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:433)
11-23 20:24:23.162: W/System.err(698):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
11-23 20:24:23.162: W/System.err(698):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
11-23 20:24:23.162: W/System.err(698):  at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
11-23 20:24:23.162: W/System.err(698):  at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
11-23 20:24:23.162: W/System.err(698):  at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
11-23 20:24:23.172: W/System.err(698):  at com.example.seminarska.Prevozi.onCreate(Prevozi.java:53)
11-23 20:24:23.172: W/System.err(698):  at android.app.Activity.performCreate(Activity.java:5008)
11-23 20:24:23.172: W/System.err(698):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
11-23 20:24:23.172: W/System.err(698):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
11-23 20:24:23.172: W/System.err(698):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
11-23 20:24:23.182: W/System.err(698):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
11-23 20:24:23.182: W/System.err(698):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
11-23 20:24:23.182: W/System.err(698):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 20:24:23.194: W/System.err(698):  at android.os.Looper.loop(Looper.java:137)
11-23 20:24:23.194: W/System.err(698):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-23 20:24:23.203: W/System.err(698):  at java.lang.reflect.Method.invokeNative(Native Method)
11-23 20:24:23.212: W/System.err(698):  at java.lang.reflect.Method.invoke(Method.java:511)
11-23 20:24:23.212: W/System.err(698):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-23 20:24:23.212: W/System.err(698):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-23 20:24:23.223: W/System.err(698):  at dalvik.system.NativeStart.main(Native Method)

The code below is the one I am using.

try {
  URL url = new URL("http://www.vogella.com");
  HttpURLConnection con = (HttpURLConnection) url
    .openConnection();
  readStream(con.getInputStream());
  } catch (Exception e) {
  e.printStackTrace();
}



private void readStream(InputStream in) {
  BufferedReader reader = null;
  try {
    reader = new BufferedReader(new InputStreamReader(in));
    String line = "";
    while ((line = reader.readLine()) != null) {
      System.out.println(line);
    }
  } catch (IOException e) {
    e.printStackTrace();
  } finally {
    if (reader != null) {
      try {
        reader.close();
      } catch (IOException e) {
        e.printStackTrace();
        }
    }
  }
} 

Any ideas what is wrong? Is there a different way to connect to the web.

  • 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-14T19:57:46+00:00Added an answer on June 14, 2026 at 7:57 pm

    You are getting this error because you’re doing a network operation, like retrieving the HTML on your main UI Thread.

    To fix it in the best way, move all network related code into a separate Thread or AsyncTask

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

Sidebar

Related Questions

I get this error when trying to connect to SQL Server. Error is: Login
I was trying out codes from Android Twitter oAuth Connect Tutorial and it worked
I'm trying to connect to a URL with a form that has this values:
I'm trying to get use of setConnectTimeout function like this: protected HttpURLConnection getConnection() throws
I am trying to retrieve the image url in from this html page The
Code: Jsoup.connect(http://www.warriorforum.com/).followRedirects(true).get(); Log cat error: 10-14 11:58:08.593: ERROR/MY(24780): TRY1: download failed java.io.IOException: Too many
Iam trying to connect my android device with a bluetooth compatible device. I know
I am trying to connect the JSF to database. This are the files web.xml
I am trying to get the facebook connect stuff working on my localhost. In
I'm trying to connect to a mongodb instance through a python socket. The url

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.