简体   繁体   English

我想测试'Crittercism'工具,我怎么能为android开发一个崩溃的应用程序?

[英]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.

相关问题 如何使用 Crittercism 手动发送异常? - How can I send an exception manually with Crittercism? 如何在不必成为默认 SMS 处理程序的情况下开发和测试 Android SMS 应用程序 - How can I develop and test an Android SMS app without having to be the default SMS handler 我想使用 PHP 开发一个 Android 聊天应用程序。 我该怎么做? 不使用 Google Firebase Cloud Messeging 和 AWS - I want to develop an Android chat app using PHP. How can I do it? without using Google Firebase Cloud Messeging and AWS 我可以从生物识别设备获取信息并使用Android应用程序计算出勤率吗? 我想开发这样的应用程序。 可能吗? - Can i take information from a Bio metric device and calculate attendance using android app. I want to develop such app. Is it possible? 我可以测试在此真实硬件设备上开发的Android应用程序吗? - Can I test Android apps that I develop on this real hardware device? 如何在android中开发带有图像的PagerSlidingTabStrip? - How can i develop the PagerSlidingTabStrip with images in android? 如何在Emacs中为Android开发? - How can I develop for Android in Emacs? 我如何在 android studio 中开发这个 - How i can develop this in android studio 我可以在没有Xcode的情况下测试/开发应用程序吗? - Can I test/develop an App without having Xcode? 我想开发一个android sdk供我们的客户使用,如何确保只有申请APP_KEY的客户才能使用我的sdk? - I want to develop a android sdk for our clients to use,how to ensure that only the client who apply for an APP_KEY can use my sdk?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM