java.lang.IllegalArgumentException: Service not registered

首先检查一下,Service是否在AndroidManifest文件中注册。格式如下:

<service   android:name=".MyService"  ></service>

如果Service已经注册了,还是会报这个错误的话,可能是

1、bindService没有成功,就直接unbindService;

2、也可能是已经unbindService成功了,还多次进行unbindService。

解决方法:

每次绑定服务时,用一个布尔值记状态为true,
解除绑定服务时,检验布尔值是否为true,如果是true,就解除服务,并把布尔值设为false,

这样即使多次解除服务,也不会报“service not registered”了。

示例代码如下:

private boolean mIsBound=false ;
public void doBindService() {
Intent bindIntent = new Intent(this, MyService.class);
bindService(bindIntent,connection,BIND_AUTO_CREATE);
mIsBound = true;
} public void doUnbindService() {
if (mIsBound) {
unbindService(mConnection);
mIsBound = false;
}
}

更详细的解答见stack overflow:

http://stackoverflow.com/questions/22079909/android-java-lang-illegalargumentexception-service-not-registered

java.lang.IllegalArgumentException: Service not registered的更多相关文章

  1. [Android]Caused by: java.lang.IllegalArgumentException: Service not registered.md

    Caused by: java.lang.IllegalArgumentException: Service not registered: org.diql.aidldemo.MainActivit ...

  2. java.lang.IllegalArgumentException: Service Intent must be explicit 解决办法

    java.lang.IllegalArgumentException: Service Intent must be explicit 意思是服务必须得显式的调用 我之前是这样使用绑定Service的 ...

  3. 错误:java.lang.IllegalArgumentException: Receiver not registered

    Caused by: java.lang.IllegalArgumentException: Receiver not registered: com.multak.cookaraclient.Mai ...

  4. java.lang.IllegalArgumentException: Service Intent must be explicit: Intent

    在Activity中启动Service的时候报错: 服务意图必须是显性声明. 这是为了防止造成冲突(i.e. 有多个Service用同样的intent-filter的情况) 这是Android 5.0 ...

  5. Android用Intent来启动Service报“java.lang.IllegalArgumentException: Service Intent must be explicit”错误的解决方法

    今天没事来写个播放器,照搬书上的原句,其中一句 //用于启动和停止service的Intent final Intent it = new Intent("android.mu.action ...

  6. Servlet.service() for servlet [jsp] in context with path [/Healthy_manager] threw exception [Unable to compile class for JSP] with root cause java.lang.IllegalArgumentException: Page directive: inval

    严重: Servlet.service() for servlet [jsp] in context with path [/Healthy_manager] threw exception [Una ...

  7. Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'jdbc.username' in string value "${jdbc.username}"

    1.启动dubbo的引用dubbo服务时候报下面这个错误,这是由于去找dubbo的发布服务未找到报的错误,所以先启动dubbo的发布服务即可. [INFO] Scanning for projects ...

  8. java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.Integer

    今天做springmvc+mybatis+spring的项目的时候发现了一个异常.如下: org.apache.ibatis.builder.IncompleteElementException: C ...

  9. java.lang.IllegalArgumentException 不合法的参数异常

    报错内容: IllegalArgumentException 不合法的参数异常 十二月 06, 2016 10:06:56 上午 org.apache.catalina.core.StandardWr ...

随机推荐

  1. Linux 期中架构 PHP

    环境 PHP安装前准备  先将需要的软件包如下位置放置.另外需要有WWW用户   参照nginx 满足以上条件后执行安装脚本 PHP安装脚本: #!/bin/bash #install PHP #au ...

  2. 1082 Read Number in Chinese (25 分)

    1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed to ...

  3. Vcenter5.5+vmwarePowercli6.5+powershell5批量创建虚拟机

    另存为xxx.ps1 ##########################通过模版批量部署虚拟机以下内容需要人工定义变量####################### #Vcenter的IP $vce ...

  4. 超链接中 utm_source, utm_medium 等参数的含义是什么?

    作者:张溪梦 Simon链接:https://www.zhihu.com/question/48724061/answer/122730629来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非 ...

  5. Spark分析之Standalone运行过程分析

    一.集群启动过程--启动Master $SPARK_HOME/sbin/start-master.sh start-master.sh脚本关键内容: spark-daemon.sh start org ...

  6. python 9*9示例

    # 9*9 乘法表# def nine_nine():#     for i in range(1, 10):#         for j in range(1, i+1):#            ...

  7. Mysql-两表的连接,copy表,select的各种用法

    -- 连接:外连接,内连接 两个表之间 外连接:right join    left join -- left join 左标为主 一般以值少的为主 select * from table1 left ...

  8. Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目

    Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...

  9. C# EF 基础操作

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. 表析LESS、Sass和Stylus的异同

    . 首页 博客园 联系我 前言:CSS预处理语言. 基本差别. 基本语法. 变量与作用域. 混合(Mixins). 嵌套实现后代选择器. 继承. 条件语句. 循环语句. 综合对比. 留言评论 返回顶部 ...