Problems with HttpClient, HttpGet and HttpResponse ...

by rustyventure » Tue, 09 Dec 2008 10:22:39 GMT


Sponsored Links
 Hi, everyone:

I'm just starting to play around with the Android SDK, but i haven't
developed any Java apps for a few years and my skills are a little
rusty ...

I'm trying some code that uses the HttpClient class. From what I've
seen from other online examples, the following code should work:

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(" http://www.google.com ");
HttpResponse response = httpclient.execute(httpget);

However, Eclipse won't let me debug this as httpclient.execute
(httpget) is underlined with an error: "Unhandled exception type
ClientProtocolException". Any ideas why I'm getting this error? Thanks
in advance!

--~--~---------~--~----~------------~-------~--~----~



Problems with HttpClient, HttpGet and HttpResponse ...

by rustyventure » Wed, 10 Dec 2008 03:49:14 GMT


 Looks like I answered my own question :)

I allowed Eclipse to auto correct my code, and it added a try - catch
routine:

HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(" http://www.google.com ");
        try {
                        HttpResponse response = httpclient.execute(httpget);
                } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

My code complies now, so I can go back to exploring :)





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. Disable battery service

Hi all,
I've ported Android on iMX28. I've no battery on board and the system
after booting notifies that battery is getting low. Anybody knows how
disable the battery service (or the battery check) in such systems
where battery is not present ?
I find a property, hw.nobattery but setting it to true (also in the
init.rc) nothing changes.

Regards

Nicola

-- 

2. Which JSON Parser is better

Hi All,

I want to use some JSON parser in my application. I get to know about
lots of available JSON parser like Android default org.json library,
JSONTokenizer, gson, jackson etc.

Is there any benifit of using gson rather than Android default parser?

I am bit confused which one of them is better keeping in mind their
usability and apk size.

Regards,
Manish

-- 

3. (Closed): WTA: Antara Soner X10 dan Motorola Milestone 1

4. atrix udah dijual

5. How can i control room lights with my android phone :)

6. Paging om renner

7. uploading files to web server working on .net using c#