On Sun, Aug 14, 2011 at 11:16 AM, Ben <ben.v...@gmail.com> wrote:Hi!

>
> ->If I try to connect to an existing address, I get the message
> "tv.append("after socket");" but just a second after that I get "08-13
> 20:44:05.657: ERROR/AndroidRuntime(304): Caused by:
> android.view.ViewRoot$CalledFromWrongThreadException: Only the original
> thread that created a view hierarchy can touch its views."
> ->If I try to connect to an address that is not existing(which is exactly
> the situation I want to simulate) I wont get any exception like "unknown
> host" or anything it just hangs and hangs and hangs withour any error or
> something till it kills my router with its trying(DDos anyone?) :D
>
>
I can help you with this bit --- you shouldn't try to manipulate the
TextView directly in
your doInBackground method.  The easiest thing to do for debugging status
messages
like these is to use Log.d and Log.e to put them in the log, and read them
out with "adb
logcat" (or the log pane in Eclipse, or whatever).  If you really do want to
display them
directly on the phone UI, the easiest thing to do is have your background
code (that is,
the doInBackground method) publishProgress(), and put the UI updates in an
onProgressUpdate() method.

(What's going on here is that the Android UI classes are not thread-safe;
manipulating
them off the activity's main thread will either get you exceptions like
this, or something
worse.  The AsyncTask machinery arranges to run onProgressUpdate on that
thread, so
UI manipulation there is safe.)

rst

-- 
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