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. How to you think about the future of PhoneGap

Hi, guys!
Today, I discover PhoneGap.Unluckily, there is no enough docement about it.
How to you think about the future of PhoneGap?
Thank you!

-- 
Believing is Everything.

-- 

2. FILENOTFOUND exception when trying to write SQLITE db

I am using the code below to read in a SQLITE db file from a website
and then output it to the apps data/databases folder.  I did something
similar to this in another app, the only difference is that instead of
the web, it read the .db file from the assets folder and that worked
just fine.  The problem I am having here is I get a filenotfound
exception after creating the outputstream.  I checked the DDMS while
the app was running and see there is no /data/data/<package>/databases
folder like with my other app so I don't know if that is the issue.  I
also tried to use the file name with a File class and perform the make
dir method but that did not create it either.  Is there something I am
missing in my manifest to let Android know that I want to use
databases?

        InputStream myInput;
          try {
            URL updateURL = new
                URL(DB_URL + dbName);
              URLConnection conn = updateURL.openConnection();
              myInput = conn.getInputStream();

                  String outFileName = DB_PATH + dbName;

                  OutputStream myOutput = new FileOutputStream(outFileName);

                  byte[] buffer = new byte[1024];
                  int length;

                  while ((length = myInput.read(buffer))>0){
                    myOutput.write(buffer, 0, length);
                  }

-- 

3. Android Market category strategy?

4. How to fix a 鈥渏ava.lang.OutOf MemoryError: bitmap size exceeds VM budget 鈥?error on andr oid

5. Need Help in Webview Highlight

6. Google Maps - hide tiles

7. @hide on PackageManager.installPackage()?