Android : java.lang.IllegalMonitorStateException: object not locked by thread before wait()?

on Monday, October 27, 2014


I am using progress dialog.i need to stop the thread when user close the progressdialog .unfortunately it giving exception pls help me..


In inner class



class UpdateThread extends Thread{

public void run() {
while (true){
count=adapter.getCount();

try {
mHandler.post( new Runnable() {
public void run() {
Log.i(TAG,count+"count");
progressDialog.setMessage(count + "Device found");
}
});
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}


Oncreate



updateThread=new UpdateThread();

progressDialog= new ProgressDialog(GroupListActivity.this);
synchronized (this) {
updateThread.start();
}


ondismissal



progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
try {
synchronized (this) {
updateThread.wait(300);
}

} catch (InterruptedException e) {
e.printStackTrace();
}
Log.i(TAG,"Thread is stopped");
}
});

0 comments:

Post a Comment