[英]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. 我想为Android开发一个基本应用程序,它必须随机崩溃以测试'crittercism'工具。 What must i do to make an app crash?
我该怎么办才能让应用程序崩溃?
Thanks. 谢谢。
Set something to null and try to use it, like: 将某些内容设置为null并尝试使用它,例如:
TextView v;
v.setText("X");
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. 在SO上关于这一点的问题很少,而且大多数答案都提出了创造性的方法来做违法行为,从而触发异常。 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 请参阅: 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). 您可以对任何已检查类型的异常执行相同操作以测试异常处理(try / catch)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.