我有以下代码,用于线程。当我运行应用程序时,我得到以下异常。
04-10 09:16:29.399: E/AndroidRuntime(14847): FATAL EXCEPTION: Thread-10
04-10 09:16:29.399: E/AndroidRuntime(14847): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
04-10 09:16:29.399: E/AndroidRuntime(14847): at android.os.Handler.<init>(Handler.java:121)
04-10 09:16:29.399: E/AndroidRuntime(14847): at android.widget.Toast.<init>(Toast.java:76)
04-10 09:16:29.399: E/AndroidRuntime(14847): at android.widget.Toast.makeText(Toast.java:251)
04-10 09:16:29.399: E/AndroidRuntime(14847): at com.mobilevoiceapps.speeddial.Class_Add_Contact$1.run(Class_Add_Contact.java:88)
04-10 09:16:29.399: E/AndroidRuntime(14847): at java.lang.Thread.run(Thread.java:1019)
这是我的代码:::
Thread myThread = new Thread(new Runnable(){
@Override
public void run()
{
try
{
while(!isLoaded)
{
Toast.makeText(Class_Add_Contact.this, "Retrieving Contacts.. Please Wait !!!", Toast.LENGTH_LONG).show();
wait(5000);
}
}
catch (Exception e)
{
}
finally{
// Exception at below line
Toast.makeText(Class_Add_Contact.this, "Retrieving Contacts Complete", Toast.LENGTH_LONG).show();
}
}
});
myThread.start();
我如何为这段代码实现处理程序?