- Thats not a good way to read a stream. look up on how to use buffers
 - Its a horrible idea to perform findViewById in a loop. you should only 
do it once before the loop.
 - never do long processes on the main thread. especially not network 
access. look up how to background tasks in android
 - setText replaces the entire text with the new value. seems more likely 
you'll want to collect all the input before you set it to the view or at 
least concat it instead of replacing it.

On Tuesday, November 20, 2012 2:43:41 PM UTC+2, Antonis Kanaris wrote:
>
>   
>    
> I am new android developer.
>
> I am trying this code for access data from my webserver....
>
> @Overridepublic void onCreate(Bundle savedInstanceState) {
>     super.onCreate(savedInstanceState);
>     setContentView(R.layout.activity_main);
>
>     URL url;
>     try {
>         url = new URL("http://www.mysite.net/LEDstate.txt";);
>
>         HttpURLConnection urlConnection = (HttpURLConnection) url
>                 .openConnection();
>
>         InputStream in = urlConnection.getInputStream();
>
>         InputStreamReader isw = new InputStreamReader(in);
>
>         int data = isw.read();
>         while (data != -1) {
>             char current = (char) data;
>             data = isw.read();
>             //System.out.print(current);
>
>
>             TextView t = (TextView) findViewById(R.id.ledstate);
>
>             t.setText(current); 
>         }
>     } catch (Exception e) {
>         // TODO Auto-generated catch block
>         e.printStackTrace();
>     }
> }
> @Overridepublic boolean onCreateOptionsMenu(Menu menu) {
>     getMenuInflater().inflate(R.menu.activity_main, menu);
>     return true;}
>
> }
>
> But data is not appearing on Screen.There is no change in Textview.
>
> I have checked Permissions they are ok.
>
> Any help? Thanks.
>

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

Reply via email to