I have problems with getting the html source code with an url. I am trying to develop an application which takes in an url and upon the button submit by the user, it takes in the url and make calls to the url provided to retrieve the html source code.
I have looked up on various methods of doing it, but have always been presented with errors using the codes provided.
Listed below is one of the codes which I have used but it doesn't seem to work for me, it will throw a Error: null in the exception when I use logcat to debug.
please pardon me if the question sounds simple, I'm new to programming. thanks in advance.
String htmlCode = "";
try {
URL url = new URL("http://www.google.com/");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
htmlCode += inputLine;
in.close();
} catch (Exception e) {
Log.d(LOG_TAG, "Error: " + e.getMessage());
}