Android:java.lang.IllegalMonitorStateException:对象在wait()之前未被线程锁定
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3792727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android: java.lang.IllegalMonitorStateException: object not locked by thread before wait()
提问by Jony
I have this this code for Android which is stuck at the synchronized statement. Even if i remove the process1.wait() i catch the exception.any help is appreciated?
我有这个 Android 代码,它被困在同步语句中。即使我删除了 process1.wait() 我也会捕获异常。感谢您的帮助吗?
private class LongOperation extends AsyncTask<String, Void, String>
{
@Override
protected String doInBackground(String... params)
{
try
{
Process process1 = new ProcessBuilder("sh", "/data/local/bin/tcpdump.sh").start();
synchronized(process1){
process1.wait();
}
}
catch (Exception e)
{
Log.e("Tcpdump function error", "Unable to capture the packets into the buffer");
}
return null;
}
/* (non-Javadoc)
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(String result)
{
try
{
StringBuffer output = new StringBuffer();
File file = new File("/data/local/bin/dump.txt");
BufferedReader br = new BufferedReader(new FileReader(file), 8 * 1024);
String line;
while ((line = br.readLine()) != null)
{
output.append(line + "\n");
}
tv.setText(output);
setContentView(tv);
}
catch (Exception e)
{
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see android.os.AsyncTask#onProgressUpdate(Progress[])
*/
@Override
protected void onProgressUpdate(Void... values)
{
}
}
The tcpdump.sh has this line tcpdump -c 10 > /data/local/bin/dump.txt
tcpdump.sh 有这一行 tcpdump -c 10 > /data/local/bin/dump.txt
采纳答案by user207421
Surely you are meaning to call Process.waitFor()?
Not wait()?
你肯定是想打电话给Process.waitFor()?
不wait()?