I want to test 'Crittercism' tool, how can i develop a crashing app for android?

397 Views Asked by At

I want to develop a basic app for Android which must crash randomly to test 'crittercism' tool. What must i do to make an app crash?

Thanks.

2

There are 2 best solutions below

4
On BEST ANSWER

Set something to null and try to use it, like:

TextView v;
v.setText("X");
0
On

There are quite few questions about this on SO, and most of the answers suggest creative ways to do something illegal that triggers the exception. I believe they are not practical, especially if you want to test for different types of exceptions.

The right way to do it is:

throw new RuntimeException("some message");

or for specific ones:

throw new IllegalStateException("some message");
throw new NullPointerException("some message");
throw new ArrayIndexOutOfBoundsException("some message");
throw new ClassCastException("some message");
...

See: https://developer.android.com/reference/java/lang/RuntimeException.html

You can do the same with any checked type of exceptions to test your exception handling (try/catch).