I am new here to Android. My application is crashing with errors after sleep runs (5000) and then my toast is not showing in my finally
block. What is causing these errors in my code?
public class LoginActivity extends ActionBarActivity {
TextView textview;
Toast toast;
@Override
protected void onCreate(Bundle ThisisLoginActivity) {
super.onCreate(ThisisLoginActivity);
setContentView(R.layout.activity_login);
textview = (TextView) findViewById(R.id.textView1);
Thread thread = new Thread() {
public void run() {
try{
sleep(5000);
} catch(InterruptedException e) {
e.printStackTrace();
}
finally {
toast = Toast.makeText(getApplicationContext(), "Sleep Runing", Toast.LENGTH_SHORT);
toast.show();
}
}
};
thread.start();
}
}
Here is my LogCat:
01-08 22:30:32.782: E/Trace(3503): error opening trace file: No such file or directory (2)
01-08 22:30:33.322: I/Choreographer(3503): Skipped 47 frames! The application may be doing too much work on its main thread.
01-08 22:30:33.402: D/gralloc_goldfish(3503): Emulator without GPU emulation detected.
01-08 22:30:33.531: I/Choreographer(3503): Skipped 62 frames! The application may be doing too much work on its main thread.
01-08 22:30:39.122: I/Choreographer(3503): Skipped 31 frames! The application may be doing too much work on its main thread.
01-08 22:30:39.272: I/Choreographer(3503): Skipped 43 frames! The application may be doing too much work on its main thread.
01-08 22:30:45.772: W/dalvikvm(3503): threadid=11: thread exiting with uncaught exception (group=0x40a71930)
01-08 22:30:45.792: E/AndroidRuntime(3503): FATAL EXCEPTION: Thread-153
01-08 22:30:45.792: E/AndroidRuntime(3503): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
01-08 22:30:45.792: E/AndroidRuntime(3503): at android.os.Handler.<init>(Handler.java:197)
01-08 22:30:45.792: E/AndroidRuntime(3503): at android.os.Handler.<init>(Handler.java:111)
01-08 22:30:45.792: E/AndroidRuntime(3503): at android.widget.Toast$TN.<init>(Toast.java:324)
01-08 22:30:45.792: E/AndroidRuntime(3503): at android.widget.Toast.<init>(Toast.java:91)
01-08 22:30:45.792: E/AndroidRuntime(3503): at android.widget.Toast.makeText(Toast.java:238)
01-08 22:30:45.792: E/AndroidRuntime(3503): at com.example.incrementdecrement.LoginActivity$1.run(LoginActivity.java:48)
01-08 22:30:46.462: I/Choreographer(3503): Skipped 34 frames! The application may be doing too much work on its main thread.