我试图运行这段代码
protected String doInBackground(String... params) {
InetAddress client = null;
boolean run = true;
String data = "";
DatagramPacket packet = null;
while( run )
{
if( data.equalsIgnoreCase( "" ) )
{
}
//Send some data
if( data.equalsIgnoreCase( "connect" ) )
{
}
//Log.d(TAG, "Data received was :" + data);
try
{
this.wait( 25 );
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
Log.d(TAG, "Error with trying to sleep");
e.printStackTrace();
}
}
Log.d(TAG, "Error with while run value");
return "finished";
}
一旦它到达 this.wait(25); 我收到这个错误
04-02 18:49:25.070: D/gameObject(9065): New game object
04-02 18:49:25.085: W/dalvikvm(9065): threadid=12: thread exiting with uncaught exception (group=0x40015560)
04-02 18:49:25.089: E/AndroidRuntime(9065): FATAL EXCEPTION: AsyncTask #2
04-02 18:49:25.089: E/AndroidRuntime(9065): java.lang.RuntimeException: An error occured while executing doInBackground()
04-02 18:49:25.089: E/AndroidRuntime(9065): at android.os.AsyncTask$3.done(AsyncTask.java:200)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.lang.Thread.run(Thread.java:1019)
04-02 18:49:25.089: E/AndroidRuntime(9065): Caused by: java.lang.IllegalMonitorStateException: object not locked by thread before wait()
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.lang.Object.wait(Native Method)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.lang.Object.wait(Object.java:395)
04-02 18:49:25.089: E/AndroidRuntime(9065): at com.example.gelorph_v1.gameServer.doInBackground(gameServer.java:116)
04-02 18:49:25.089: E/AndroidRuntime(9065): at com.example.gelorph_v1.gameServer.doInBackground(gameServer.java:1)
04-02 18:49:25.089: E/AndroidRuntime(9065): at android.os.AsyncTask$2.call(AsyncTask.java:185)
04-02 18:49:25.089: E/AndroidRuntime(9065): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
04-02 18:49:25.089: E/AndroidRuntime(9065): ... 4 more
为什么会发生这种情况?
帆布