Thanks to Murphy M for the solution to my problem. It worked like a charm. On Jun 14, 12:10 pm, Mark Murphy <mmur...@commonsware.com> wrote: > Use runOnUiThread() around your code in the catch block, to have that > stuff be done on the main application thread. > > > > > > On Tue, Jun 14, 2011 at 6:40 AM, Droid <rod...@gmail.com> wrote: > > I am spinning a thread to go online and get data. But if phone is in a > > network hole (no signal) it throws an exception. > > In the exception I try to call Toast or finish() the activity but both > > those cause a crash. > > > Here's the error and my code: > > error is: > > 06-14 11:32:01.691: ERROR/AndroidRuntime(7389): > > java.lang.RuntimeException: Can't create handler inside thread that > > has not called Looper.prepare() > > > here is the code, note the catch clause at the end which is where my > > problem lies: > > > *************************************************************************** > > ****************** > > private Thread checkUpdate = new Thread() { > > public void run() { > > try { > > URL updateURL = new URL("http://search.twitter.com/ > > search.json?q="+string_from_speaker); > > URLConnection conn = updateURL.openConnection(); > > ... > > } catch (Exception e) { > > // none of these exception handlers work becaue they are in wrong > > thread!! WTF? > > // NOPE tv1.setText(" having trouble getting online"); // TODO > > // NOPE Toast.makeText(IconicAgain.this, "having trouble getting > > online "+ e, Toast.LENGTH_LONG).show(); > > } > > } > > }; > > *************************************************************************** > > ***************** > > > Can I at least stop this thread somehow? Or close the activity > > somehow? > > > -- > > 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 > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > Android Training in NYC:http://marakana.com/training/android/
-- 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