I got the same issue yesterday for a similar code
I believe the emulator couldn't connect to internet.
uninstalling the app doing a clean build and restarting the emulator
fixed the problem.
make sure you have put uses permisson internet.
restartng
On Mar 25, 4:02 am, "g...@deanblakely.com" <g...@deanblakely.com>
wrote:
> The code pasted below gets an exception on tha line that says...
> InputStream in = new
> BufferedInputStream(urlConnection.getInputStream());
> It's an IO exception that says: java.net.UnknownHostException:www.android.com
>
> I checked and that is a valid url.  I got the original code from the
> android docs on HttpURLConnection although I had to fix serveral bugs
> in the docs code.
>
> Why am I getting this exception?
> thanks,
> Gary
>
> import java.io.BufferedInputStream;
> import java.io.ByteArrayOutputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import java.net.HttpURLConnection;
> import java.net.MalformedURLException;
> import java.net.URL;
>
> import android.app.Activity;
> import android.os.Bundle;
>
> public class HelloAndroid extends Activity {
>     /** Called when the activity is first created. */
>     @Override
>     public void onCreate(Bundle savedInstanceState)
>     {
>         super.onCreate(savedInstanceState);
>         setContentView(R.layout.main);
>
>         HttpURLConnection urlConnection = null;
>
>                         try
>                         {
>                                 URL url = new URL("http://www.android.com/";);
>                                 urlConnection = (HttpURLConnection) 
> url.openConnection();
>                                 InputStream in = new
> BufferedInputStream(urlConnection.getInputStream());
>                                 readStream(in);
>                         }
>                         catch (MalformedURLException e)
>                         {
>                                 // TODO Auto-generated catch block
>                                 e.printStackTrace();
>                         }
>                         catch (IOException e)
>                         {
>                                 e.printStackTrace();
>                         }
>
>                 finally
>                 {
>                         urlConnection.disconnect();
>                 }
>     }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to