Q:

IllegalArgumentException in Android

I am using the following code to obtain an Http Response in an Android app.
 HttpGet get = new HttpGet(targetURL); 
 HttpClient httpclient = new DefaultHttpClient();
 HttpResponse response = httpclient.execute(get);
 String responseBody = EntityUtils.toString(response.getEntity());

But  HttpResponse response = httpclient.execute(get); is throwing an java.lang.IllegalArgumentException: Host name may not be null
Any help on what is going wrong?

A:

You are missing the "scheme" part of your URI. All URIs require a scheme:
http://en.wikipedia.org/wiki/Uniform_resource_identifier#Syntax

The URI syntax consists of a URI scheme name (such as "http", "ftp", "mailto", "crid" or "file") followed by a colon character, and then by a scheme-specific part. 

Add http:// on to your String, so make it http://localhost:8080
HttpGet throws an IllegalArgumentException if the URI is invalid, so that's exactly what is happening.
HttpGet documentation

