cannot handle exception type PackageManager.NameNotFoundException thrown by implicit super construct
来源:互联网 发布:软件项目付款申请 编辑:程序博客网 时间:2024/06/05 10:38
别人拿来给我改的代码,在类属性里放了这么一段:
final PackageManager pm = getPackageManager();
final PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);
ApplicationInfo ai = pi.applicationInfo;
int uid = ai.uid;
long a = TrafficStats.getUidRxBytes(uid);
long b = TrafficStats.getUidTxBytes(uid);
final PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);报了这么个错误:
Default constructor cannot handle exception type PackageManager.NameNotFoundException thrown by implicit super constructor. Must define an explicit constructor
翻看API,看到PackageManager 是个虚类,getPackageInfo是个虚方法。原本以为错就在这里了。
不过也许在别处实现了这个方法呢?虽然API中没说明何处实现了它,这个有点坑,但是,应该不至于这么坑吧。。。
然后看错误内容,是说父类构造器是显式的,所以子类也不能用默认构造器,所以就出现了 NameNotFoundException。
尼玛,这是要我去给加个构造器的节奏吗?这不是坑爹嘛~
但是,为毛线有异常没有 出现 try-catch?
因为这段代码是放在域中的。
移到函数里去加上异常处理就ok了。
但是既然说出现了未处理的异常,为什么没有第一时间想到去捕获处理它?
因为习惯了用eclipse自动加上异常处理。
习惯了在执行报错后加上全局的异常捕获。
所以形成了思维定势。
为什么形成思维定势?因为编程这门学问太博大精深了,编程的时候脑子一点都不敢跳。
所以说,编程这玩意真不适合我。。。
- cannot handle exception type PackageManager.NameNotFoundException thrown by implicit super construct
- Java中异常Default constructor cannot handle exception type UnsupportedEncodingException thrown by impli
- 【Android Exception】android.content.pm.PackageManager$NameNotFoundException
- Exception of type System.OutOfMemoryException was thrown.
- Exception of type 'System.OutOfMemoryException' was thrown
- 处理Exception of type System.OutOfMemoryException was thrown
- Exception has been thrown by the target of an invocation
- SharePoint debug - Unhandled exception was thrown by the sandboxed code ...
- java-No exception of type ConfigurationException can be thrown; an exception type must be a subclass
- [INFO] Exception Thrown When Trying To Deserialize An Object Whose Type Is Defined In An Assembly Which Is Loaded By Assembly.Lo
- No exception of type JmsException can be thrown; an exception type must be a subclass of Throwable
- No exception of type HibernateException can be thrown; an exception type must be a subclass of Thro
- No exception of type BeansException can be thrown; an exception type must be a sunclass of Throwable
- Unhandled Exception thrown
- 一个错误的解决:Exception thrown by getter for property author of bean buyregister
- Exception thrown by getter for property customer.name of bean book
- Exception thrown by getter for property, bean org.apache.struts.taglib.html.BEAN
- ASPxGridView Exception has been thrown by the target of an invocation
- git 命令
- 深入解析Apache Mina源码(4)——Mina编解码以及对粘包和断包的处理
- 青岛泽雨你到底怎么了???人去楼空了,难道真的要倒闭了吗?
- Codeforces Round #277.5 (Div. 2)-B
- 初级会计实务试题要怎么复习
- cannot handle exception type PackageManager.NameNotFoundException thrown by implicit super construct
- android权限大全
- svn 冲突解决
- 省市级联--jquery调取json数据
- Linux字符串操作大全
- 警告: 程序集绑定日志记录被关闭。
- Android开发教程:shape和selector的结合使用
- 传智---Haoop--(2)--能做什么
- sourceinsight 显示完整文件路径