0

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.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
ufukcakir
  • 61
  • 2
  • 11

2 Answers2

2

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

TextView v;
v.setText("X");
Geobits
  • 22,218
  • 6
  • 59
  • 103
Rick Falck
  • 1,778
  • 3
  • 15
  • 19
  • Thanks. I laughed because there are so many questions on SO, where people ask "why did my app crash", and that is the reason. – Rick Falck Dec 16 '13 at 09:39
  • i see, who wants his app to crash you thought.. i am new to android tools and want to discover how things work with crittercism.. – ufukcakir Dec 16 '13 at 09:42
  • Hey again. Is there any alternative ways to make app crash? – ufukcakir Dec 16 '13 at 11:47
  • @ufukcakir Just search for crashes in the `[android]` tag here. There are about a million and one ways to make it crash. – Geobits Dec 16 '13 at 16:29
0

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