Showing a Toast using "setUncaughtExceptionHandler"
Posted
by VitalyB
on Stack Overflow
See other posts from Stack Overflow
or by VitalyB
Published on 2010-06-13T22:36:55Z
Indexed on
2010/06/13
22:42 UTC
Read the original article
Hit count: 329
Hi everyone,
I'm trying to do a simple global exception handler in my Android app and I am having troubles:
public class TicTacToe extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Toast.makeText(this, "TOAST", Toast.LENGTH_LONG);
}
});
setContentView(R.layout.main);
}
}
I'm a rather new with both Android AND java but in .NET that would work. Can't I access local variable from anonymous methods in java? If so, how should I rewrite it?
Thanks, Vitaly
© Stack Overflow or respective owner