Android Error : Can't create handler inside thread that has not called Looper.prepare()
I am Creating one thread inside my Click event. I want to call my webservice rep开发者_JS百科eatedly on particular time thats why i am using Timer event inside my click event but it throws exception that java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() . if i can not call timer in click event then please give me some hint to do so here is my code
holder.linear.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mo.equals(BUDDYNAMECOPY.get(BUDDYNAMECOPY.indexOf(mo)))) {
INDEX = BUDDYNAMECOPY.indexOf(mo);
B_Id = BUDDYLIST.get(INDEX).getBuddyUID();
tim.schedule(new TimerTask() {
@Override
public void run() {
CurrentLocation location =new CurrentLocation(getApplicationContext());
lat=location.getCurrentLatitude();
lon=location.getCurrentLongitude();
String url=UrlConstant.BASEURL + UrlConstant.GET_LATLONG
+ JsonDataProcessor.uid + "&buddy_uid="
+ B_Id;
JsonDataProcessor caller=new JsonDataProcessor(url,BuddyList.this,UrlConstant.BUDDYLOCATION);
}
},0,30000);
}
}
});
精彩评论