Andrioid开发过程中关于IntentService的问题
2015-09-01 20:14
337 查看
在Android开发中,笔者曾经遇到过
Unable to instantiate service
com.example.helloservice.HelloIntentService:
java.lang.InstantiationException: can’t instantiate class
com.example.helloservice.HelloIntentService; no empty constructor
这个问题,想了半天没找到解决办法。
后来查了书,原来是我的一个继承了IntentService的类使用了带参数的构造函数导致运行出错,
就顺利解决了问题啦!
Unable to instantiate service
com.example.helloservice.HelloIntentService:
java.lang.InstantiationException: can’t instantiate class
com.example.helloservice.HelloIntentService; no empty constructor
这个问题,想了半天没找到解决办法。
后来查了书,原来是我的一个继承了IntentService的类使用了带参数的构造函数导致运行出错,
public class HelloIntentService extends IntentService { public HelloIntentService(String name) { //(1) super(name); // TODO 自动生成的构造函数存根 } @Override protected void onHandleIntent(Intent intent) { // TODO 自动生成的方法存根 System.out.println("休息8秒"); try { Thread.sleep(8000); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } } //(1)部分的代码改为 public HelloIntentService() {//继承IntentService类必须要创建无参构造函数 super(“HelloIntentService”); }
就顺利解决了问题啦!
相关文章推荐
- oracle11g dataguard安装实施
- 007-spark的wordCount
- 机器学习 径向基(Radial basis function)与RBF核函数 浅析
- 算法:插入排序
- HTTP请求头和响应头总结
- 从上往下打印二叉树(分层遍历)
- OPS - add pubkey to the server with script
- ZOJ2321解题报告
- codeforces 337E E. Divisor Tree(数论+贪心)
- EasyX
- 005-spark standalone模式安装
- hihocoder1224
- 【工业串口和网络软件通讯平台(SuperIO)教程】九.重写通讯接口函数,实现特殊通讯方式
- 人工智能学习梵高,毕加索风格,画出的世界名画是什么样子
- MyBatis——日志
- 外碎片与内碎片
- 页面之间传值方式的总结,五种方式,通知,block,代理,单例,NSUERDEFALUT,
- Android UI设计小知识——渐变色背景的制作
- 交换排序------冒泡排序(实现Java)
- Zookeeper Api(java)入门与应用