错误日志:

 Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=m4 (has extras) }
                                                                              at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1809)
                                                                              at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1838)
                                                                              at android.app.ContextImpl.startService(ContextImpl.java:1822)
                                                                              at android.content.ContextWrapper.startService(ContextWrapper.java:516)
                                                                              at myapplication.com.canvas.MainActivity.start(MainActivity.java:24)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at java.lang.reflect.Method.invoke(Method.java:372)
                                                                              at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:284)
                                                                              at android.view.View.performClick(View.java:4793)
                                                                              at android.view.View$PerformClick.run(View.java:19960)
                                                                              at android.os.Handler.handleCallback(Handler.java:739)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:135)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5593)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at java.lang.reflect.Method.invoke(Method.java:372)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:967)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

补充代码:

<1> 配置文件:

  <service android:name=".service.FirstService" >
<intent-filter>
<action android:name="m4" />
</intent-filter>
</service>

<2>

public class FirstService extends Service {
/*
* intent:startServcie(it)传入的值
* startId:启动服务的次数序号
*
*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) { int x = intent.getIntExtra("x", 0);
//System.out.println("--"+startId+"--"+x);
if (x==88) {
//停止服务
stopSelf();
}
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
System.out.println("--onDestroy");
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
} }

<3>

public class MainActivity extends AppCompatActivity {

    TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
public void start(View v){
Intent it=new Intent();
it.setAction("m4");
it.putExtra("x", 88); startService(it);
}
}

错误修改:

 public void start(View v){
Intent it=new Intent();
it.setAction("m4");
it.putExtra("x", 88);
it.setPackage("myapplication.com.canvas");//应用的包名
startService(it);
}

Service错误的更多相关文章

  1. service mysql start出错,mysql启动不了,解决mysql: unrecognized service错误

    service mysql start出错,mysql启动不了,解决mysql: unrecognized service错误的方法如下: [root@ctohome.com ~]# service ...

  2. 安装tomcat出现failed to install tomcat8 service错误及解决方法

    failed to install tomcat8 service 如下图所示:     一.安装tomcat出现failed to install tomcat6 service错误及解决方法(转载 ...

  3. dubbo rest服务 No provider available for the service 错误问题

    1.版本 dubbo 2.6.2 2.描述 消费者调用dubbo rest服务报No provider available for the service错误 网络上有讲是实体类未实现Serializ ...

  4. 【mysql】service mysql start出错,mysql启动不了,解决mysql: unrecognized service错误

    service MySQL start出错,mysql启动不了,解决mysql: unrecognized service错误的方法如下: [root@ctohome.com ~]# service ...

  5. 第一次安装tomcat报错,出现failed to install tomcat8 service错误

    第一次安装tomcat报错,出现failed to install tomcat8 service错误(0) 一.一般情况下这种错误都是没有卸载干净造成的,安全卸载Tomcat的方法 (转载); ht ...

  6. 安装mysql会出现start service错误

    安装MySQL时无法启动服务(could not start the service MYSQL .Error:0)安装mysql会出现start service错误安装mysql时 配置到start ...

  7. 没有启动 ASP.NET State service错误的解决方法

    具体错误如下: 异常详细信息: System.Web.HttpException: 无法向会话状态服务器发出会话状态请求.请确保已启动 ASP.NET State service,并且客户端和服务器端 ...

  8. 安装tomcat出现failed to install tomcat6 service错误及解决方法(转载)

    安装安装版tomcat会出现failed to install tomcat6 service ,check your setting and permissio的概率是非常低的,但是最近楼主就老出现 ...

  9. 解决java.lang.NoClassDefFoundError: javax/xml/rpc/service错误的方法

    最近在做WebService项目,本地测试没有问题,打算部署到服务器上,但是部署后,访问时出现了如下图1的错误: 图1 图1报的是没有找到定义的类的错误.刷新页面有又出现了另外“新”的错误: 图2 根 ...

随机推荐

  1. *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory

    报错提示: *** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndex ...

  2. Struts2版本配置2.1以前与以后---关于filter的配置

    严重: Dispatcher initialization failed java.lang.RuntimeException JavaStrutsfreemarkerApacheXML  严重: D ...

  3. <meta>标签元素的属性理解

    meta是用来在HTML文档中模拟HTTP协议的响应头报文.meta 标签用于网页的<head>与</head>中,meta 标签的用处很多.meta 的属性有两种:name和 ...

  4. centos 7.0 安装

    最小化安装的  主要查看硬盘使用时间 需要安装 smartmontools 这个 [root@localhost ~]# yum install -y smartmontools 已加载插件:fast ...

  5. thinkphp 3.2 视图模型 实例 视图查询结果 二维数组 合并

    使用视图模型查询的时候 结果是这样的 array(6) { [0] => array(5) { ["picTitle"] => string(7) "标题2& ...

  6. 开源项目管理平台*redmine*的架设

    yum -y install ruby yum install rubygems gem install heroku gem install rack -v=1.0.1 gem install ru ...

  7. android自定义控件(7)-获取自定义ImageView的src属性

    创建一个自定义组件,继承 ImageView.在我的 xml 布局文件中是这样设置的: <Mycomponent android:src="@drawable/my_test_imag ...

  8. [MongoDB]Profiling性能分析

    摘要 上篇文章介绍了mapReduce这个聚合操作.本篇将继续学习,db有了,collection和document也有,基本上够用了,但是随着项目上线后,发现业务数据越来越多,查询效率越来越慢,这时 ...

  9. 导入excel错误:外部表不是预期的格式 解决方案

    环境:win7+iis7+Office2007 在asp.net网站中导出Excel文件后,再把文件导入到数据库中. 读取Excel文件时,打开连接出错. 错误为:外部表不是预期的格式 解决:检查了一 ...

  10. ASP.NET Web API与Owin OAuth:调用与用户相关的Web API(非第三方登录)

    授权完成添加属性 ClaimsIdentity oAuthIdentity = await CreateAsync(user/*userManager*/, OAuthDefaults.Authent ...