【问题标题】:Getting error source/class not found找不到错误源/类
【发布时间】:2011-03-04 10:23:09
【问题描述】:

我在我的程序中使用服务,我在 Mainactivity 中有 MainActivity.java 和 MyService.java 我将意图称为

public void onClick(View src)
    {
        switch (src.getId()) {
        case R.id.ButtonStart:
            Log.d(TAG, "onClick: starting service");
            startService(new Intent(this,com.example.MyService1.class));
            break;
        case R.id.ButtonStop:
            Log.d(TAG,"onClick: stopping service");
            stopService(new Intent(this,com.example.MyService1.class));
            break;

        }
    }

但我在 Log.d 上收到错误消息“WARN/ActivityManager(68): Unable to start service Intent { cmp=com.example/.MyService1 }: not found”请告诉我解决方案。

【问题讨论】:

    标签: android


    【解决方案1】:

    您正在使用文件 MyService.java 并像这样启动服务:

    startService(new Intent(this,com.example.MyService1.class));
    

    现在确定您为什么在这里使用com.example.MyService1.class 而不是MyService

    只需像这样使用:startService(new Intent(this,MyService.class));

    【讨论】:

      【解决方案2】:

      确保您在 AndroidManifest.xml 文件中声明了您的服务。

      <service android:name="com.example.MyService1"/>

      【讨论】:

        猜你喜欢
        • 2013-08-18
        • 1970-01-01
        • 1970-01-01
        • 2011-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-24
        相关资源
        最近更新 更多