Android Studio中未处理的异常警告 [英] Android Studio unhandled exception warnings

查看:266
本文介绍了Android Studio中未处理的异常警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我进入某些行像的JSONObject 解码或日期解析,应用程序将无法编译,因为编译器给出了一个 UnhandledException 警告,我必须包装在 try / catch块呼叫前应用程序编译。这可以被禁用,因此,我并不需要写在 try / catch块

When I enter certain lines like JSONObject decoding or date parsing, the app will not compile as the compiler gives an UnhandledException warning and I have to wrap the call in a try/catch block before the app will compile. Can this be disabled so that I don't need to write the try/catch block?

推荐答案

正如我在评论说不要紧 Android的工作室的Eclipse 或任何其他的IDE,同时使用code这显示出错误,你应该使用的try / catch 块,你无法禁用它。你应该只添加块,并改变你的code,所以你可以,如果这个异常是程序执行的某些点抛出妥善处理您的函数或类的其余部分。

As I said in the comment doesn't matter if you are using Android Studio or Eclipse or any other IDE, while using code which showing error where you should wrap your code with try / catch block, you can't disable this. You should just add the block and change your code so you can handle the rest of your function or class properly if this exception is thrown in some point of program execution.

有关抛在Java中捕获异常你可以阅读更多有关在这里:

For throwing and catching exceptions in Java you can read more about here:

Java编程:抛出和捕获异常

和更好地解释其中的异常应该与包裹的try / catch 块和没有,这里有两个很好的例子:

and for better explanation of which exceptions should be wrapped with try/catch block and which not, here are two good examples:

Java的异常处理和的 Java异常

这篇关于Android Studio中未处理的异常警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆