Your use of HttpGet is good.
However, you cast an InputStream to a char-sequence when calling
tv.setText((CharSequence)input);.
This will give you a class-cast exception. Read char-data from the
InputStream instead.

Also, try to find out if 'entity' has some methods to get a String
back that has the content of the HttpResponse. Then you can skip
handling the InputStream and reading a string from it.


Also, did you give your app internet-permission?

On Mar 21, 5:10 pm, murphy <howt...@hotmail.com> wrote:
> Hi all, I am having difficulty retrieving data from the internet to be
> displayed in a TextView. When I run the application it says the
> application has stopped unexpectedly. I am using the code:
>
> String urls = "http://www.indulec.ie/weather.txt";;
>
>             HttpClient client = new DefaultHttpClient();
>
>             // Create a method instance.
>             HttpGet method = new HttpGet(urls);
>             method.getParams().setIntParameter
> (CoreConnectionPNames.CONNECTION_TIMEOUT, 10000 );
>             method.getParams().setIntParameter
> (CoreConnectionPNames.SO_TIMEOUT, 10000 );
>             method.getParams().setIntParameter
> (CoreConnectionPNames.SOCKET_BUFFER_SIZE, 200000 );
>             method.getParams().setIntParameter
> (ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, 5 );
>             method.getParams().setIntParameter
> (ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 10 );
>
>             HttpResponse response = null;
>             InputStream input = null;
>
>             try
>             {
>                 response = client.execute( method );
>                 HttpEntity entity = response.getEntity();
>                 input = entity.getContent();
>
>                 TextView tv = (TextView)findViewById(R.id.somenews);
>                 tv.setText((CharSequence) input);
>
>                 setContentView(R.layout.latestnews);
>
>             }
>             catch ( IOException e )
>             {
>                 Log.d("", "Can not connect to the target server!" );
>                 try {
>                                         throw new IOException();
>                                 } catch (IOException e1) {
>                                         // TODO Auto-generated catch block
>                                         e1.printStackTrace();
>                                 }
>             }
>             finally
>             {
>                 Log.d("", "close Expired Connections!" );
>                 client.getConnectionManager().closeExpiredConnections
> ();
>             }
--~--~---------~--~----~------------~-------~--~----~
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