ufukcakir
ufukcakir

Reputation: 61

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

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.

Upvotes: 0

Views: 378

Answers (2)

user3386180
user3386180

Reputation:

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).

Upvotes: 0

Rick Falck
Rick Falck

Reputation: 1778

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

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

Upvotes: 2

Related Questions