java - Thread exiting due uncaught exception -


hy!

my code:

thread thread = new thread (){             @override             public void run() {                 while (true)                 {                     handler handler = new handler(){                           @override                           public void handlemessage(message msg) {                               if (msg.obj.tostring()!= null)                              {                              jsonparse json = null;                              try {                                 log.e("channel_state",msg.obj.tostring());                                  json = new jsonparse(msg.obj.tostring());                                 string state = json.getchannelstate();                                 id = state;                                  textview tv2 = (textview)findviewbyid(r.id.mainscreen_state);                                  tv2.settext("channel state: "+ state);                                 log.e("state",state);                             } catch (final exception e) {                                 // todo auto-generated catch block                                 e.printstacktrace();                                 runonuithread(new  runnable() {                                     public void run() {                                         toast toast ;                                         toast =     toast.maketext(getapplicationcontext(), "error" + e.getmessage(), 500);                                         log.e("error",e.getmessage());                                         toast.show();                                     }                                 });                             }                               }                              else                              {                                 runonuithread(new  runnable() {                                 public void run() {                                     toast toast ;                                     toast =     toast.maketext(getapplicationcontext(), "error", 500);                                      toast.show();                                 }                             });                              }                           }                           };                      list<namevaluepair> params = new arraylist<namevaluepair>();                     params.add(new basicnamevaluepair("session_id", settings.getstring("session_id","error")));                     params.add(new basicnamevaluepair("channel_id",string.valueof(settings.getint("channel_id", -1))));                     httpconnection con = new httpconnection(params, "http://surfkid.redio.de/getchannelimage", handler);                     con.start();                     try {                         log.e("sleep","begin");                         this.sleep(5000);                         log.e("sleep","end");                      } catch (interruptedexception e) {                         // todo auto-generated catch block                         log.e("sleep","fail");                     }                  }             }         };         thread.start(); 

log:

02-10 00:01:29.044: error/androidruntime(1248): uncaught handler: thread thread-13 exiting due uncaught exception 02-10 00:01:29.054: error/androidruntime(1248): java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare() 02-10 00:01:29.054: error/androidruntime(1248):     @ android.os.handler.<init>(handler.java:121) 02-10 00:01:29.054: error/androidruntime(1248):     @ android.skiptvad.mainscreen$6$1.<init>(mainscreen.java:258) 02-10 00:01:29.054: error/androidruntime(1248):     @ android.skiptvad.mainscreen$6.run(mainscreen.java:258) 

please help!

seems want doing creating handlerthread

handlerthread mythread = new handlerthread(); mythread.start(); handler myhandler = new handler(mythread.getlooper()){ //your handler code. } 

this should give thread handled handler in way looking for.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -