我有这个Android代码,它停留在synchronized语句中。即使我删除了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)
{
}
}
tcpdump.sh有这一行 tcpdump -c 10&gt; /data/local/bin/dump.txt
答案 0 :(得分:3)
您肯定打电话给Process.waitFor()?
而不是wait()?