Reading content from a URL failing

I am trying to read a JSON from a web page and store it as a string, however when debugging it keeps failing in the try statement at line:

BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

public String networkRequest() throws IOException { URL url = new URL(""); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); try { InputStream inputStream = url.openStream(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); StringBuilder stringBuilder = new StringBuilder(); int cp; while ((cp = != -1) { stringBuilder.append((char) cp); } return stringBuilder.toString(); } catch(Exception ex) { return "nothing"; } }

In which because of the fail reaches the catch and returns "nothing", does anyone understand what I am doing wrong?

BTW: My network is perfectly fine!

-------------Problems Reply------------

Great. It means you are executing this method from UI thread which is not recommended and android strict mode will not allow this. Hence there is an exception. Please execute the method from a background thread.

Category:android Views:9 Time:2018-11-30

Related post

  • Wait until page is loaded before reading contents from a URL in Java 2011-09-07

    I am reading from a url in my java code but the page I want to read executes a command when loaded and the InputStreamReader reads the page before it has completely loaded, so my buffered reader only collects the HTML on the page before the real cont

  • Reading content from URL with Node.js 2011-06-09

    I'm trying to read the content from a URL with Node.js but all I seem to get are a bunch of bytes. I'm obviously doing something wrong but I'm not sure what. This is the code I currently have: var http = require('http'); var client = http.createClien

  • Extract contents from the url using JSOUP 2011-09-01

    I want to extract contents from a url and this is the below content that I want to extract using jsoup. And I want to extract text of <div id =content> <div id="content"> <!-- Start: Header --> <div id="content-group_header-0" cl

  • how to read image from particular url in android 2010-12-15

    how to read image from particular url in android? --------------Solutions------------- Use this URL url = new URL(imageUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream is = connection.getInputStream(); Bitmap

  • How to read content from ms word files using Jakarta POI 2011-02-14

    I've included jakarta-poi-1.5.1-final-20020615.jar file to read content from ms word. I am unable to do this ...can anyone help me? --------------Solutions------------- Here is quick guide You need to move to a newer version of POI - the one you're o

  • How to make simultaneous ajax request to get JSON content from different URL's 2011-05-25

    I need to make 10 simultaneous ajax request to get JSON content from different URL's. Each request response is not dependent on each others. In this case how do I manage those requests?? I try using AjaxManager plugin but I can't configure it right t

  • parsing specific content from a url(webpage) in php, javascript 2011-06-07

    I use some RSS feeds. Some of them don't have a description for their articles. In order not to show just the title and no description for those articles, I would like to show for example the first two paragraphs of the actual article. I experimented

  • How to get content from gowalla url? 2011-07-06

    How to get content from gowalla url in php or javascript? Like this: --------------Solutions------------- Try using these functions: Using cURL function get_data($url) { $ch = cu

  • Extract some contents from the url using regular expressions in java 2011-09-01

    I want to extract contents from this url and this is the below content that I want to extract using regular expression. String expr = " What Regular Expression should I use here "; Pattern patt = Pattern.compile(expr,

  • Get a part of content from a url 2011-10-18

    I don't know if you are able to do this, but... Is there anyway to get a part of the content from a URL ? Like if I have this: <protected>false</protected> <followers_count>6</followers_count> <profile_background_color>0

  • IE keep reading content from and 2012-07-03

    Dear all, When I broswing some page, the toolbar will show that the IE is keep on reading content from and facebook. What is the problem? I have try to reinstall IE but the problem still exist. Please Help. hon123456 --------------So

  • Android. Reading content from file 2012-09-08

    I'm using the next method to read content from a file. The problem here is that i'm limited to ht unmber of characters specified for inputBuffer (in this case 1024). First of all, if the content is less than 1024 chars long, i get a lot of whitespace

  • What is the preferred way to read/write content from a URL in Java 2010-05-18

    What is the preferred way to open a connection to a website and then subsequently read the information on that page? There seem to be many specific questions about different parts, but no clear and simple examples. --------------Solutions------------

  • Android Read contents of a URL (content missing after in result) 2010-01-19

    I have the following code that reads the content of a url public static String DownloadText(String url){ StringBuffer result = new StringBuffer(); try{ URL jsonUrl = new URL(url); InputStreamReader isr = new InputStreamReader(jsonUrl.openStream()); B

  • Reading content from file 2010-07-30

    NSString *contentPath = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@"rtf"]; NSData *databuffer; NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:contentPath]; if (file == nil) NSLog(@"Failed to open file"); databuffer = [file

  • Download Content From External URL and save in db with Ruby 2010-08-21

    This isn't webservices. I want to pass a url to a controller and then have it fetch the html from that page. Then store the information in a db. What do you think? How can I accomplish this? --------------Solutions------------- In your controller: ht

  • simplest way to read json from a URL in java 2010-11-29

    This might be a dumb question but what is the simplest way to read and parse JSON from URL in Java? In Groovy, it's a matter of few lines of code. Java examples that I find are ridiculously long (and have huge exception handling block). All I want to

  • Read XML from a URL in PHP with cURL 2011-03-23

    I want to read XML data from a URL in Magento. I have three textboxes. One is for baseurl and others are for username and password respectively. when i enter these values i get url like "

  • Get file content from a URL? 2011-04-02

    When I use following URL in browser then it prompt me to download a text file with JSOn content.,40&chl=Hello|World&chof=json (Click above URL see downloaded file content)

  • read data from a url and stream it back to client with ruby on rails 2011-11-04

    I'm still new to Ruby and Rails so please excuse my question if the answer is obvious. I have an application running with a controller called bucket which when passed an id connects to a non-routable subnet (10.0.0.xx) and returns data assuming some

  • read content from Twitter sample using Javascript 2012-05-01

    I'm pretty new to programming, and recently have been playing with Twitter API. From statuses/sample method, how would you read the content of following URL using Javascript? Edit: perhaps I shall exp

  • oracle Reading Directly from a URL code not working properly 2013-02-09

    I'm trying to learn how to download images and files from a website trough a java program. The code below is copied from This program is supposed to display the html file code fr

  • read parameters from friendly url in Struts2 2010-01-05

    Using Convention Plugin, I am able to achieve friendly URL in Struts2. Now, I want to read the parameter from the URL. How to acheive this. Regards Ganesh --------------Solutions--------

  • Get content from a url using php 2010-02-01

    I want to get the dynamic contents from a particular url: I have used the code echo $content=file_get_contents(''); I am getting following results: document.write('"Bakers have a great knead to make bre

  • extract xml data/content from a url using shell scripting 2011-03-15

    I need the xml content to be downloaded in file.xml from a url .say for example this is the url I want to extract the xml content of it as follows to a file.xml <?xml version="1.0" encoding="ISO-88

Copyright (C), All Rights Reserved.

processed in 0.067 (s). 11 q(s)